Package org.jadice.util.swing.button
Class JButtonGroup
- java.lang.Object
-
- javax.swing.ButtonGroup
-
- org.jadice.util.swing.button.JButtonGroup
-
- All Implemented Interfaces:
Serializable
public class JButtonGroup extends ButtonGroup
JButtonGroup
is an useful enhanced version of its ancestor classButtonGroup
. It provides the possibility to listen to button group and selection changes, but also it allows to clear the button group selection.- Author:
- Carolin Köhler
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class javax.swing.ButtonGroup
buttons
-
-
Constructor Summary
Constructors Constructor Description JButtonGroup()
Creates an emptyJButtonGroup
JButtonGroup(AbstractButton[] buttons)
Creates aJButtonGroup
object from an array of buttons and adds the buttons to the group.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(AbstractButton button)
Adds a button to the groupvoid
add(AbstractButton[] buttons)
Adds an array of buttons to the groupvoid
addChangeListener(ChangeListener l)
Adds aChangeListener
to the button.void
clearSelection()
Clears the current selection.boolean
contains(AbstractButton button)
Checks whether the group contains the given buttonprotected void
fireStateChanged()
Notifies all listeners that have registered interest for notification on this event type.AbstractButton
getButton(ButtonModel model)
Returns theAbstractButton
whoseButtonModel
is given.int
getButtonCount()
List<AbstractButton>
getButtons()
Returns the buttons in the group as aList
AbstractButton
getSelected()
Returns the selected button in the group.ButtonModel
getSelection()
boolean
isSelected(AbstractButton button)
Returns whether the button is selectedvoid
remove(AbstractButton button)
Removes a button from the groupvoid
remove(AbstractButton[] buttons)
Removes all the buttons in the array from the groupvoid
removeChangeListener(ChangeListener l)
Removes aChangeListener
from the button.void
setSelected(AbstractButton button, boolean selected)
Sets the selected button in the group Only one button in the group can be selectedvoid
setSelected(ButtonModel model, boolean selected)
Sets the selected button model in the group-
Methods inherited from class javax.swing.ButtonGroup
getElements, isSelected
-
-
-
-
Constructor Detail
-
JButtonGroup
public JButtonGroup()
Creates an emptyJButtonGroup
-
JButtonGroup
public JButtonGroup(AbstractButton[] buttons)
Creates aJButtonGroup
object from an array of buttons and adds the buttons to the group. No button will be selected initially.- Parameters:
buttons
- an array ofAbstractButton
s
-
-
Method Detail
-
addChangeListener
public void addChangeListener(ChangeListener l)
Adds aChangeListener
to the button.- Parameters:
l
- the listener to add
-
removeChangeListener
public void removeChangeListener(ChangeListener l)
Removes aChangeListener
from the button.- Parameters:
l
- the listener to remove
-
fireStateChanged
protected void fireStateChanged()
Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.- See Also:
EventListenerList
-
add
public void add(AbstractButton button)
Adds a button to the group- Overrides:
add
in classButtonGroup
- Parameters:
button
- anAbstractButton
reference
-
add
public void add(AbstractButton[] buttons)
Adds an array of buttons to the group- Parameters:
buttons
- an array ofAbstractButton
s
-
remove
public void remove(AbstractButton button)
Removes a button from the group- Overrides:
remove
in classButtonGroup
- Parameters:
button
- the button to be removed
-
remove
public void remove(AbstractButton[] buttons)
Removes all the buttons in the array from the group- Parameters:
buttons
- an array ofAbstractButton
s
-
setSelected
public void setSelected(AbstractButton button, boolean selected)
Sets the selected button in the group Only one button in the group can be selected- Parameters:
button
- anAbstractButton
referenceselected
- anboolean
representing the selection state of the button
-
setSelected
public void setSelected(ButtonModel model, boolean selected)
Sets the selected button model in the group- Overrides:
setSelected
in classButtonGroup
- Parameters:
model
- aButtonModel
referenceselected
- anboolean
representing the selection state of the button
-
getButton
public AbstractButton getButton(ButtonModel model)
Returns theAbstractButton
whoseButtonModel
is given. If the model does not belong to a button in the group, returns null.- Parameters:
model
- aButtonModel
that should belong to a button in the group- Returns:
- an
AbstractButton
reference whose model ismodel
if the button belongs to the group,null
otherwise
-
getSelected
public AbstractButton getSelected()
Returns the selected button in the group.- Returns:
- a reference to the currently selected button in the group or
null
if no button is selected
-
getSelection
public ButtonModel getSelection()
- Overrides:
getSelection
in classButtonGroup
-
isSelected
public boolean isSelected(AbstractButton button)
Returns whether the button is selected- Parameters:
button
- anAbstractButton
reference- Returns:
true
if the button is selected,false
otherwise
-
getButtons
public List<AbstractButton> getButtons()
Returns the buttons in the group as aList
- Returns:
- a
List
containing the buttons in the group, in the order they were added to the group
-
contains
public boolean contains(AbstractButton button)
Checks whether the group contains the given button- Parameters:
button
-- Returns:
true
if the button is contained in the group,false
otherwise
-
clearSelection
public void clearSelection()
Clears the current selection.- Overrides:
clearSelection
in classButtonGroup
-
getButtonCount
public int getButtonCount()
- Overrides:
getButtonCount
in classButtonGroup
- See Also:
ButtonGroup.getButtonCount()
-
-