Package uk.ac.starlink.util.gui
Class ValueButtonGroup<T>
java.lang.Object
javax.swing.ButtonGroup
uk.ac.starlink.util.gui.ValueButtonGroup<T>
- All Implemented Interfaces:
Serializable
Extends ButtonGroup by associating a value with each button.
- Since:
- 11 Jan 2005
- Author:
- Mark Taylor
- See Also:
-
Field Summary
Fields inherited from class javax.swing.ButtonGroup
buttons
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(AbstractButton button, T value) Adds a button and associates a value with it.void
addChangeListener
(ChangeListener listener) Adds a listener which will be notified whenever this group's selected value changes.getValue()
Returns the currently selected value, that is the value associated with the currently selected button.void
remove
(AbstractButton button) void
removeChangeListener
(ChangeListener listener) Removes a listener previously added byaddChangeListener
.void
Sets the currently selected value.Methods inherited from class javax.swing.ButtonGroup
add, clearSelection, getButtonCount, getElements, getSelection, isSelected, setSelected
-
Constructor Details
-
ValueButtonGroup
public ValueButtonGroup()Constructor.
-
-
Method Details
-
add
Adds a button and associates a value with it. Whenbutton
is selected,getValue()
will returnvalue
. You can usenull
for a value, but don't have two buttons with associated values which are equal.- Parameters:
button
- buttonvalue
- associated value
-
remove
- Overrides:
remove
in classButtonGroup
-
getValue
Returns the currently selected value, that is the value associated with the currently selected button.- Returns:
- selected value
-
setValue
Sets the currently selected value. The associated button will be selected (and others deselected).value
must be one of the values associated with a button in this group.- Parameters:
value
- new value
-
addChangeListener
Adds a listener which will be notified whenever this group's selected value changes.- Parameters:
listener
- listener to add
-
removeChangeListener
Removes a listener previously added byaddChangeListener
.- Parameters:
listener
- listener to remove
-