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 ButtonGroup
buttons -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(AbstractButton button, T value) Adds a button and associates a value with it.voidaddChangeListener(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.voidremove(AbstractButton button) voidremoveChangeListener(ChangeListener listener) Removes a listener previously added byaddChangeListener.voidSets the currently selected value.Methods inherited from class 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. Whenbuttonis selected,getValue()will returnvalue. You can usenullfor a value, but don't have two buttons with associated values which are equal.- Parameters:
button- buttonvalue- associated value
-
remove
- Overrides:
removein 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).valuemust 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
-