javax.swing
public class ButtonGroup extends Object implements Serializable
ButtonGroup can be selected at the same time. If one
button in a ButtonGroup is selected, all other buttons
are automatically deselected.
While ButtonGroup can be used for all buttons that are derived
from {@link AbstractButton}, it is normally only used for
{@link JRadioButton}s, {@link JRadioButtonMenuItem}s and
{@link JToggleButton}s.
You could use it for {@link JCheckBox}es, but for the sake of usability
this is strongly discouraged because the common expectation of checkboxes
is that the user is allowed to make multiple selections.
It makes no sense to put {@link JButton}s or {@link JMenuItem}s in
a ButtonGroup because they don't implement the
selected semantics.
| Field Summary | |
|---|---|
| protected Vector<AbstractButton> | buttons Stores references to the buttons added to this button group. |
| Constructor Summary | |
|---|---|
| ButtonGroup()
Creates a new button group. | |
| Method Summary | |
|---|---|
| void | add(AbstractButton b)
Adds a button to this group. |
| int | getButtonCount()
Return the number of buttons in this button group.
|
| Enumeration<AbstractButton> | getElements()
Returns the currently added buttons.
|
| ButtonModel | getSelection()
Returns the currently selected button model.
|
| boolean | isSelected(ButtonModel m)
Checks if the given ButtonModel is selected in this button
group.
|
| void | remove(AbstractButton b)
Removes the specified button from this group. |
| void | setSelected(ButtonModel m, boolean b)
Sets the currently selected button model. |
Parameters: b the button to add (null is ignored).
Returns: the number of buttons
Since: 1.3
Returns: Enumeration over all added buttons
Returns: the currently selected button model, null if none was selected yet
ButtonModel is selected in this button
group.
Parameters: m the button model (null permitted).
Returns: true if m is the selected button model
in this group, and false otherwise.
null.
The group for the removed button's model is set to null.
Parameters: b the button to remove (null is ignored).
Parameters: m the model to select b true if this button is to be selected, false otherwise