|
Groovy Documentation | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjavax.swing.ButtonGroup
com.wordpress.tipsforjava.swing.SelectButtonGroup
public class SelectButtonGroup extends ButtonGroup
This class is used to create a multiple-exclusion scope for a set of buttons.
Creating a set of buttons with the same SelectButtonGroup object
means that selecting one of those buttons deselects all other buttons in the
group.
This class provides useful methods not available in
javax.swing.ButtonGroup to simultaneously enable or disable all
the buttons in the group, to listen for a change of selected button by adding
a PropertyChangeListener, and to obtain the selected index as an
int, facilitating switch-case processing.
A SelectButtonGroup can be used with any set of objects that
inherit from AbstractButton. Typically a button group contains
instances of JRadioButton, JRadioButtonMenuItem,
or JToggleButton. It wouldn't make sense to put an instance of
JButton or JMenuItem in a button group because
JButton and JMenuItem don't implement the selected
state.
When a SelectButtonGroup is no longer required, #dispose() should be invoked to release static references to the buttons it contains.
Extends ButtonGroup.
| Field Summary | |
|---|---|
static Vector |
allButtons
The collection of all buttons present in SelectedButtonGroups |
protected boolean |
enabled
The enabled state of the buttons in the group |
private SwingPropertyChangeSupport |
propertyChangeSupport
all propertyChangeSupport goes through this. |
AbstractButton |
selectedButton
The currently selected button. |
| Constructor Summary | |
SelectButtonGroup()
Creates a new |
|
| Method Summary | |
|---|---|
void
|
add(AbstractButton button)
Adds the button to the group. |
void
|
addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list. |
void
|
clearSelection()
Clears the selection such that none of the buttons in the
|
void
|
dispose()
Removes all the buttons from the group |
void
|
finalize()
Ensures that the |
protected void
|
firePropertyChanged(String propertyName, Object oldValue, Object newValue)
Support for reporting bound property changes for Object properties. |
PropertyChangeListener[]
|
getPropertyChangeListeners()
Returns an array of all the property change listeners registered on this group. |
AbstractButton
|
getSelectedButton()
Gets the current selected button from this group. |
int
|
getSelectedIndex()
Returns the index of the selected button. |
boolean
|
isSelected(AbstractButton button)
Returns whether a |
void
|
remove(AbstractButton button)
Removes the button from the group. |
void
|
removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list. |
void
|
setEnabled(boolean enable)
Enables or disables all the buttons in this group, depending on the value of the parameter enable. |
void
|
setSelected(ButtonModel model, boolean selected)
Sets the selected value for the |
void
|
setSelectedButton(AbstractButton button)
Sets the selected value for the |
void
|
setSelectedIndex(int index)
Sets the group's selected index to index. |
| Methods inherited from class ButtonGroup | |
|---|---|
| add, remove, getElements, isSelected, setSelected, clearSelection, getSelection, getButtonCount, wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
| Methods inherited from class Object | |
|---|---|
| wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
| Field Detail |
|---|
static Vector allButtons
protected boolean enabled
private SwingPropertyChangeSupport propertyChangeSupport
AbstractButton selectedButton
| Constructor Detail |
|---|
public SelectButtonGroup()
SelectButtonGroup.
| Method Detail |
|---|
@Override public void add(AbstractButton button)
button - the button to be added
public void addPropertyChangeListener(PropertyChangeListener listener)
If listener is null,
no exception is thrown and no action is performed.
listener - the property change listener to be added
@Override public void clearSelection()
SelectButtonGroup are selected.
public void dispose()
It is recommended to invoke this method when the group is no longer required. This releases static references to the buttons of the group.
@Override public void finalize()
dispose method of this group is called when
there are no more refrences to it.
protected void firePropertyChanged(String propertyName, Object oldValue, Object newValue)
PropertyChangeEvent to any registered
PropertyChangeListeners.
propertyName - the property whose value has changedoldValue - the property's previous valuenewValue - the property's new value
public PropertyChangeListener[] getPropertyChangeListeners()
PropertyChangeListeners
or an empty array if no property change
listeners are currently registered
public AbstractButton getSelectedButton()
AbstractButton in this group that is currently
in the selected state, or null if there is no currently
selected button.
AbstractButton that is currently in the
selected state, or null.
public int getSelectedIndex()
public boolean isSelected(AbstractButton button)
Button is selected.
true if the button is selected,
otherwise returns false
@Override public void remove(AbstractButton button)
button - the button to be removed
public void removePropertyChangeListener(PropertyChangeListener listener)
If listener is null, no exception is thrown and no action is performed.
listener - the PropertyChangeListener to be removed
public void setEnabled(boolean enable)
@Override public void setSelected(ButtonModel model, boolean selected)
ButtonModel. Only one button
in the group may be selected at a time.
Notifies any listeners if the model changes
model - the ButtonModelselected - true if this button is to be
selected, otherwise false
public void setSelectedButton(AbstractButton button)
AbstractButton. Only one
button in the group may be selected at a time.
Notifies any listeners if the model changes
button - the AbstractButton
public void setSelectedIndex(int index)
Notifies any listeners if the model changes
index - an int specifying the model selection
Groovy Documentation