Determining the Selected JRadioButton in a Button Group : JRadioButton « Swing « Java Tutorial






import java.util.Enumeration;

import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;

public class Main {
  public static void main(String[] argv) throws Exception {
  }

  public static JRadioButton getSelection(ButtonGroup group) {
    for (Enumeration e = group.getElements(); e.hasMoreElements();) {
      JRadioButton b = (JRadioButton) e.nextElement();
      if (b.getModel() == group.getSelection()) {
        return b;
      }
    }
    return null;
  }
}








14.9.JRadioButton
14.9.1.Creating JRadioButton Components
14.9.2.Using JRadioButtonUsing JRadioButton
14.9.3.Grouping JRadioButton Components in a ButtonGroupGrouping JRadioButton Components in a ButtonGroup
14.9.4.Determining the Selected JRadioButton in a Button Group
14.9.5.Listening to JRadioButton Events with an ActionListenerListening to JRadioButton Events with an ActionListener
14.9.6.Reference to the last selected item and check for reselectionReference to the last selected item and check for reselection
14.9.7.Listening to JRadioButton Events with a ChangeListenerListening to JRadioButton Events with a ChangeListener
14.9.8.Listening to JRadioButton Events with an ItemListenerListening to JRadioButton Events with an ItemListener
14.9.9.Event sequence: Action Event, Item Event and Change EventEvent sequence: Action Event, Item Event and Change Event
14.9.10.Getting selected JRadioButton in a containerGetting selected JRadioButton in a container
14.9.11.Customizing JRadioButton Look and Feel