Java JButton Settings setSelectedSilently(AbstractButton x, boolean b)

Here you can find the source of setSelectedSilently(AbstractButton x, boolean b)

Description

set Selected Silently

License

LGPL

Declaration

public static void setSelectedSilently(AbstractButton x, boolean b) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.awt.event.ActionListener;
import java.awt.event.ItemListener;

import javax.swing.AbstractButton;

public class Main {
    public static void setSelectedSilently(AbstractButton x, boolean b) {
        ActionListener[] al = x.getActionListeners();
        if (al != null && al.length > 0) {
            for (ActionListener a : al)
                x.removeActionListener(a);
        }/*from w w w  . ja  va2  s .  c  o  m*/
        ItemListener[] il = x.getItemListeners();
        if (il != null && il.length > 0) {
            for (ItemListener a : il)
                x.removeItemListener(a);
        }
        x.setSelected(b);
        if (al != null && al.length > 0) {
            for (ActionListener a : al)
                x.addActionListener(a);
        }
        if (il != null && il.length > 0) {
            for (ItemListener a : il)
                x.addItemListener(a);
        }
    }
}

Related

  1. setPreferredWidth(JComponent button, int minWidth)
  2. setRadioButtonSelected(Window window, String buttonText)
  3. setScaledIcon(final AbstractButton button, final ImageIcon icon, final int orientation, final double scale)
  4. setSelected(final AbstractButton abstractButton, final boolean isSelected)
  5. setSelectedButton(ButtonGroup group, int index)
  6. setToggleGroups(final JToggleButton... buttons)
  7. setToggling(AbstractButton b)
  8. setWithoutNotifyingListeners(AbstractButton button, boolean selected)
  9. showJFileChooser(javax.swing.JFileChooser chooser, java.awt.Component parent, java.lang.String approveButtonText)