Package rma.swing
Class JButtonGroup
java.lang.Object
javax.swing.ButtonGroup
rma.swing.JButtonGroup
- All Implemented Interfaces:
Serializable
Extends
javax.swing.ButtonGroup to provide methods that allow working with button references instead of button models.- See Also:
-
Field Summary
Fields inherited from class javax.swing.ButtonGroup
buttons -
Constructor Summary
ConstructorsConstructorDescriptionCreates an emptyJButtonGroupJButtonGroup(AbstractButton[] buttons) Creates aJButtonGroupobject from an array of buttons and adds the buttons to the group No button will be selected initially. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(AbstractButton button) Adds a button to the groupvoidadd(AbstractButton[] buttons) Adds an array of buttons to the groupbooleancontains(AbstractButton button) Checks whether the group contains the given buttongetButton(ButtonModel model) Returns theAbstractButtonwhoseButtonModelis given.Returns the buttons in the group as aListReturns the selected button in the group.booleanisSelected(AbstractButton button) Returns whether the button is selectedvoidremove(AbstractButton button) Removes a button from the groupvoidremove(AbstractButton[] buttons) Removes all the buttons in the array from the groupvoidsetSelected(AbstractButton button, boolean selected) Sets the selected button in the group Only one button in the group can be selectedvoidsetSelected(ButtonModel model, boolean selected) Sets the selected button model in the groupMethods inherited from class javax.swing.ButtonGroup
clearSelection, getButtonCount, getElements, getSelection, isSelected
-
Constructor Details
-
JButtonGroup
public JButtonGroup()Creates an emptyJButtonGroup -
JButtonGroup
Creates aJButtonGroupobject from an array of buttons and adds the buttons to the group No button will be selected initially.- Parameters:
buttons- an array ofAbstractButtons
-
-
Method Details
-
add
Adds a button to the group- Overrides:
addin classButtonGroup- Parameters:
button- anAbstractButtonreference
-
add
Adds an array of buttons to the group- Parameters:
buttons- an array ofAbstractButtons
-
remove
Removes a button from the group- Overrides:
removein classButtonGroup- Parameters:
button- the button to be removed
-
remove
Removes all the buttons in the array from the group- Parameters:
buttons- an array ofAbstractButtons
-
setSelected
Sets the selected button in the group Only one button in the group can be selected- Parameters:
button- anAbstractButtonreferenceselected- anbooleanrepresenting the selection state of the button
-
setSelected
Sets the selected button model in the group- Overrides:
setSelectedin classButtonGroup- Parameters:
model- aButtonModelreferenceselected- anbooleanrepresenting the selection state of the button
-
getButton
Returns theAbstractButtonwhoseButtonModelis given. If the model does not belong to a button in the group, returns null.- Parameters:
model- aButtonModelthat should belong to a button in the group- Returns:
- an
AbstractButtonreference whose model ismodelif the button belongs to the group,nullotherwise
-
getSelected
Returns the selected button in the group.- Returns:
- a reference to the currently selected button in the group or
nullif no button is selected
-
isSelected
Returns whether the button is selected- Parameters:
button- anAbstractButtonreference- Returns:
trueif the button is selected,falseotherwise
-
getButtons
Returns the buttons in the group as aList- Returns:
- a
Listcontaining the buttons in the group, in the order they were added to the group
-
contains
Checks whether the group contains the given button- Returns:
trueif the button is contained in the group,falseotherwise
-