public class JButtonGroup extends javax.swing.ButtonGroup
javax.swing.ButtonGroup
to provide methods that allow working
with button references instead of button models.
Modified by Joseph A. Huwaldt, Date: September 16, 2012ButtonGroup
,
Serialized FormConstructor and Description |
---|
JButtonGroup()
Creates an empty
JButtonGroup |
JButtonGroup(javax.swing.AbstractButton[] buttons)
Creates a
JButtonGroup object from an array of buttons and adds the
buttons to the group No button will be selected initially. |
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
|
javax.swing.AbstractButton |
getButton(javax.swing.ButtonModel model)
Returns the
AbstractButton whose
ButtonModel is given. |
java.util.List<javax.swing.AbstractButton> |
getButtons()
Returns the buttons in the group as a
List |
javax.swing.AbstractButton |
getPreviousSelected()
Returns the button that was selected prior to the currently selected
button in the group.
|
javax.swing.AbstractButton |
getSelected()
Returns the selected button in the group.
|
boolean |
isEnabled()
Returns true if any button in this button group is enabled.
|
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 |
setEnabled(boolean flag)
Enables or disables all the buttons in this button 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 JButtonGroup()
JButtonGroup
public JButtonGroup(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 final 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 javax.swing.AbstractButton getPreviousSelected()
null
if no button was selected prior to the currently
selected button.public boolean isSelected(javax.swing.AbstractButton button)
button
- an
AbstractButton
referencetrue
if the button is selected,
false
otherwisepublic java.util.List<javax.swing.AbstractButton> getButtons()
List
List
containing the buttons in the group, in the order they
were added to the grouppublic boolean contains(javax.swing.AbstractButton button)
true
if the button is contained in the group,
false
otherwisepublic void setEnabled(boolean flag)
public boolean isEnabled()