javaswinguser-interfacelistenerjtogglebutton

How to untoggle jtogglebuttons on second click that belongs to ButtonGroups


How to untoggle jtogglebuttons that belongs to ButtonGroups on second click? What listener should I use for this? Thanks!

JtoggleButton toggleButton;

toggleButton.addActionListener? toggleButton.addChangeListener?


Solution

  • public class CustomButtonGroup extends ButtonGroup {
      @Override
      public void setSelected(ButtonModel model, boolean selected) {
        if (selected) {
          super.setSelected(model, selected);
        } else {
          clearSelection();
        }
      }
    }