Remove all action listeners from a button Swing AbstractButton. - Java Swing

Java examples for Swing:Action

Description

Remove all action listeners from a button Swing AbstractButton.

Demo Code


//package com.java2s;
import java.awt.event.ActionListener;
import javax.swing.AbstractButton;

public class Main {
    /**/*w  w w  .j av a  2 s  . c  o  m*/
     * Remove all action listeners from a button.
     * 
     * @param button Button.
     */
    public static void removeActionListeners(AbstractButton button) {
        if (button == null) {
            return;
        }
        ActionListener[] listeners = button.getActionListeners();
        if (listeners == null) {
            return;
        }
        for (ActionListener listener : listeners) {
            button.removeActionListener(listener);
        }
    }
}

Related Tutorials