public class ButtonGroup extends Object implements ActionSource<ActionEvent>
This class is used to create a multiple-exclusion scope for
RadioButton
.
Creating a set of RadioButton
components with the same ButtonGroup
object
means that only one RadioButton
can be selected among those within
the specific ButtonGroup
.
Constructor and Description |
---|
ButtonGroup()
Creates a new instance of ButtonsGroup
|
ButtonGroup(RadioButton... rb)
Adds all the radio buttons to the group
|
Modifier and Type | Method and Description |
---|---|
void |
add(RadioButton rb)
Adds a RadioButton to the group
|
void |
addActionListener(ActionListener<ActionEvent> al)
Adds an action listener to all the buttons in the group
|
void |
addAll(RadioButton... rb)
Adds the RadioButtons to the group
|
void |
clearSelection()
Clears the selection such that none of the buttons in the ButtonGroup are selected.
|
int |
getButtonCount()
Returns the number of buttons in the group.
|
RadioButton |
getRadioButton(int index)
Returns the radio button at the given group index
|
RadioButton |
getSelected()
Return the selected radio button within the group
|
int |
getSelectedIndex()
Return the index of the selected button within the group
|
boolean |
isSelected()
Returns whether a radio button in the group is selected.
|
void |
remove(RadioButton rb)
removes a RadioButton from the group
|
void |
removeActionListener(ActionListener<ActionEvent> al)
Removes an action listener from all the buttons in the group
|
void |
setSelected(int index)
Sets the selected Radio button by index
|
void |
setSelected(RadioButton rb)
Selects the given radio button
|
public ButtonGroup()
public ButtonGroup(RadioButton... rb)
rb
- public void addAll(RadioButton... rb)
rb
- a RadioButtons to addpublic void add(RadioButton rb)
rb
- a RadioButton to addpublic void remove(RadioButton rb)
rb
- a RadioButton to removepublic void clearSelection()
public int getButtonCount()
public boolean isSelected()
public int getSelectedIndex()
public RadioButton getSelected()
public RadioButton getRadioButton(int index)
index
- offset within the group starting with 0 and no larger than getButtonCount()public void setSelected(RadioButton rb)
rb
- the radio button to set as selectedpublic void setSelected(int index)
index
- the index of the radio button to mark as selectedpublic void addActionListener(ActionListener<ActionEvent> al)
addActionListener
in interface ActionSource<ActionEvent>
al
- the listenerpublic void removeActionListener(ActionListener<ActionEvent> al)
removeActionListener
in interface ActionSource<ActionEvent>
al
- the listener