![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e770. Determining the Selected JRadioButton in a Button GroupWhen you ask a button group for the currently selected radio button, it returns the selected radio button's model (rather than the selected radio button itself). Fortunately, the button group maintains the list of buttons and so you can iterate over this list looking for one with the same model.// This method returns the selected radio button in a button group 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; }
e769. Selecting a JRadioButton Component in a Button Group e771. Determining If a JRadioButton Component Is Selected e772. Adding an Icon to the Label of a JRadioButton Component e773. Customizing the Icons in a JRadioButton Component © 2002 Addison-Wesley. |