public class JButtonGroup extends ButtonGroup
JButtonGroup
is an useful enhanced version of its ancestor class
ButtonGroup
. It provides the possibility to listen to button group and
selection changes, but also it allows to clear the button group selection.buttons
Constructor and Description |
---|
JButtonGroup()
Creates an empty
JButtonGroup |
JButtonGroup(AbstractButton[] buttons)
Creates a
JButtonGroup object from an array of buttons and adds the buttons to the
group. |
Modifier and Type | Method and Description |
---|---|
void |
add(AbstractButton button)
Adds a button to the group
|
void |
add(AbstractButton[] buttons)
Adds an array of buttons to the group
|
void |
addChangeListener(ChangeListener l)
Adds a
ChangeListener to the button. |
void |
clearSelection()
Clears the current selection.
|
boolean |
contains(AbstractButton button)
Checks whether the group contains the given button
|
protected void |
fireStateChanged()
Notifies all listeners that have registered interest for notification on this event type.
|
AbstractButton |
getButton(ButtonModel model)
Returns the
AbstractButton whose ButtonModel is given. |
int |
getButtonCount() |
List<AbstractButton> |
getButtons()
Returns the buttons in the group as a
List |
AbstractButton |
getSelected()
Returns the selected button in the group.
|
ButtonModel |
getSelection() |
boolean |
isSelected(AbstractButton button)
Returns whether the button is selected
|
void |
remove(AbstractButton button)
Removes a button from the group
|
void |
remove(AbstractButton[] buttons)
Removes all the buttons in the array from the group
|
void |
removeChangeListener(ChangeListener l)
Removes a
ChangeListener from the button. |
void |
setSelected(AbstractButton button,
boolean selected)
Sets the selected button in the group Only one button in the group can be selected
|
void |
setSelected(ButtonModel model,
boolean selected)
Sets the selected button model in the group
|
getElements, isSelected
public JButtonGroup()
JButtonGroup
public JButtonGroup(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 addChangeListener(ChangeListener l)
ChangeListener
to the button.l
- the listener to addpublic void removeChangeListener(ChangeListener l)
ChangeListener
from the button.l
- the listener to removeprotected void fireStateChanged()
EventListenerList
public void add(AbstractButton button)
add
in class ButtonGroup
button
- an AbstractButton
referencepublic void add(AbstractButton[] buttons)
buttons
- an array of AbstractButton
spublic void remove(AbstractButton button)
remove
in class ButtonGroup
button
- the button to be removedpublic void remove(AbstractButton[] buttons)
buttons
- an array of AbstractButton
spublic void setSelected(AbstractButton button, boolean selected)
button
- an AbstractButton
referenceselected
- an boolean
representing the selection state of the buttonpublic void setSelected(ButtonModel model, boolean selected)
setSelected
in class ButtonGroup
model
- a ButtonModel
referenceselected
- an boolean
representing the selection state of the buttonpublic AbstractButton getButton(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 AbstractButton getSelected()
null
if no
button is selectedpublic ButtonModel getSelection()
getSelection
in class ButtonGroup
public boolean isSelected(AbstractButton button)
button
- an AbstractButton
referencetrue
if the button is selected, false
otherwisepublic List<AbstractButton> getButtons()
List
List
containing the buttons in the group, in the order they were added
to the grouppublic boolean contains(AbstractButton button)
button
- true
if the button is contained in the group, false
otherwisepublic void clearSelection()
clearSelection
in class ButtonGroup
public int getButtonCount()
getButtonCount
in class ButtonGroup
ButtonGroup.getButtonCount()
Copyright © 2024 levigo holding gmbh. All rights reserved.