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 AbstractButton, it is normally only used for
JRadioButtons, JRadioButtonMenuItems and
JToggleButtons.
You could use it for JCheckBoxes, 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 JButtons or JMenuItems in
a ButtonGroup because they don't implement the
selected semantics.| Modifier and Type | Field and Description |
|---|---|
protected Vector<AbstractButton> |
buttons
Stores references to the buttons added to this button group.
|
| Constructor and Description |
|---|
ButtonGroup()
Creates a new button group.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
protected Vector<AbstractButton> buttons
public ButtonGroup()
public void add(AbstractButton b)
b - the button to add (null is ignored).public void remove(AbstractButton b)
null.
The group for the removed button's model is set to null.b - the button to remove (null is ignored).public Enumeration<AbstractButton> getElements()
Enumeration over all added buttonspublic ButtonModel getSelection()
public void setSelected(ButtonModel m, boolean b)
m - the model to selectb - true if this button is to be selected, false otherwisepublic boolean isSelected(ButtonModel m)
ButtonModel is selected in this button
group.m - the button model (null permitted).true if m is the selected button model
in this group, and false otherwise.public int getButtonCount()