Google Tag Manager

2017/02/27

Click on the already selected JToggleButton and clear all selections in the ButtonGroup

Code

class ToggleButtonGroup extends ButtonGroup {
  private ButtonModel prevModel;
  private boolean isAdjusting;
  @Override public void setSelected(ButtonModel m, boolean b) {
    if (isAdjusting) {
      return;
    }
    if (m.equals(prevModel)) {
      isAdjusting = true;
      clearSelection();
      isAdjusting = false;
    } else {
      super.setSelected(m, b);
    }
    prevModel = getSelection();
  }
}

References

No comments:

Post a Comment