Java JButton Settings setToggling(AbstractButton b)

Here you can find the source of setToggling(AbstractButton b)

Description

Set the specified button such that it alternates between being selected and not whenever it is pushed.

License

Open Source License

Declaration

public static synchronized void setToggling(AbstractButton b) 

Method Source Code

//package com.java2s;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractButton;

public class Main {
    /** Our lazily-initialized toggling action listener. */
    protected static ActionListener _toggler;

    /**// ww w  .j  a  v  a 2s  .  com
     * Set the specified button such that it alternates between being selected and not whenever it
     * is pushed.
     */
    public static synchronized void setToggling(AbstractButton b) {
        if (_toggler == null) {
            _toggler = new ActionListener() {
                public void actionPerformed(ActionEvent event) {
                    AbstractButton but = (AbstractButton) event.getSource();
                    but.setSelected(!but.isSelected());
                }
            };
        }

        b.addActionListener(_toggler);
    }
}

Related

  1. setScaledIcon(final AbstractButton button, final ImageIcon icon, final int orientation, final double scale)
  2. setSelected(final AbstractButton abstractButton, final boolean isSelected)
  3. setSelectedButton(ButtonGroup group, int index)
  4. setSelectedSilently(AbstractButton x, boolean b)
  5. setToggleGroups(final JToggleButton... buttons)
  6. setWithoutNotifyingListeners(AbstractButton button, boolean selected)
  7. showJFileChooser(javax.swing.JFileChooser chooser, java.awt.Component parent, java.lang.String approveButtonText)
  8. showJFileChooser(JFileChooser chooser, Component parent, String approveButtonText)
  9. showOptions(int width, int type, String title, String text, Object... buttons)