public class JButtonGroup
extends javax.swing.ButtonGroup
javax.swing.ButtonGroup
to provide methods
that allow working with button references instead of button models.ButtonGroup
,
Serialized FormConstructor and Description |
---|
JButtonGroup()
Creates an empty
JButtonGroup |
Modifier and Type | Method and Description |
---|---|
void |
add(javax.swing.AbstractButton button)
Adds a button to the group
|
void |
add(javax.swing.AbstractButton[] buttons)
Adds an array of buttons to the group
|
boolean |
contains(javax.swing.AbstractButton button)
Checks whether the group contains the given button
|
static JButtonGroup |
create(javax.swing.AbstractButton[] buttons)
Creates a
JButtonGroup object from an array
of buttons and adds the buttons to the group. |
javax.swing.AbstractButton |
getButton(javax.swing.ButtonModel model)
Returns the
AbstractButton whose ButtonModel is given. |
java.util.List |
getButtons()
Returns the buttons in the group as a
List |
javax.swing.AbstractButton |
getSelected()
Returns the selected button in the group.
|
boolean |
isSelected(javax.swing.AbstractButton button)
Returns whether the button is selected
|
void |
remove(javax.swing.AbstractButton button)
Removes a button from the group
|
void |
remove(javax.swing.AbstractButton[] buttons)
Removes all the buttons in the array from the group
|
void |
setSelected(javax.swing.AbstractButton button,
boolean selected)
Sets the selected button in the group
Only one button in the group can be selected
|
void |
setSelected(javax.swing.ButtonModel model,
boolean selected)
Sets the selected button model in the group
|
public static JButtonGroup create(javax.swing.AbstractButton[] buttons)
JButtonGroup
object from an array
of buttons and adds the buttons to the group.
No button will be selected initially.buttons
- an array of AbstractButton
spublic void add(javax.swing.AbstractButton button)
add
in class javax.swing.ButtonGroup
button
- an AbstractButton
referencepublic void add(javax.swing.AbstractButton[] buttons)
buttons
- an array of AbstractButton
spublic void remove(javax.swing.AbstractButton button)
remove
in class javax.swing.ButtonGroup
button
- the button to be removedpublic void remove(javax.swing.AbstractButton[] buttons)
buttons
- an array of AbstractButton
spublic void setSelected(javax.swing.AbstractButton button, boolean selected)
button
- an AbstractButton
referenceselected
- an boolean
representing the selection state of the buttonpublic void setSelected(javax.swing.ButtonModel model, boolean selected)
setSelected
in class javax.swing.ButtonGroup
model
- a ButtonModel
referenceselected
- an boolean
representing the selection state of the buttonpublic javax.swing.AbstractButton getButton(javax.swing.ButtonModel model)
AbstractButton
whose ButtonModel
is given.
If the model does not belong to a button in the group, returns null.model
- a ButtonModel
that should belong to a button in the groupAbstractButton
reference whose model
is model
if the button belongs to the group, null
otherwisepublic javax.swing.AbstractButton getSelected()
null
if no button is selectedpublic boolean isSelected(javax.swing.AbstractButton button)
button
- an AbstractButton
referencetrue
if the button is selected,
false
otherwisepublic java.util.List getButtons()
List
List
of the buttons in the group,
in the order they were added to the grouppublic boolean contains(javax.swing.AbstractButton button)
button
- the given buttontrue
if the button is in the group,
false
otherwise