/**
* Clears the selection such that none of the buttons
* in the <code>ButtonGroup</code> are selected.
*
* @since 1.6
*/
public void clearSelection() {
if (selection != null) {
ButtonModel oldSelection = selection;
selection = null;
oldSelection.setSelected(false);
}
}
/**
* Returns all the buttons that are participating in
* this group.
* @return an <code>Enumeration</code> of the buttons in this group
*/
public Enumeration<AbstractButton> getElements() {
return buttons.elements();
}
/**
* Returns the model of the selected button.
* @return the selected button model
*/
public ButtonModel getSelection() {
return selection;
}
/**
* Sets the selected value for the <code>ButtonModel</code>.
* Only one button in the group may be selected at a time.
* @param m the <code>ButtonModel</code>
* @param b <code>true</code> if this button is to be
* selected, otherwise <code>false</code>
*/
public void setSelected(ButtonModel m, boolean b) {
if (b && m != null && m != selection) {
ButtonModel oldSelection = selection;
selection = m;
if (oldSelection != null) {
oldSelection.setSelected(false);
}
m.setSelected(true);
}
}
/**
* Returns whether a <code>ButtonModel</code> is selected.
* @return <code>true</code> if the button is selected,
* otherwise returns <code>false</code>
*/
public boolean isSelected(ButtonModel m) {
return (m == selection);
}
/**
* Returns the number of buttons in the group.
* @return the button count
* @since 1.3
*/
public int getButtonCount() {
if (buttons == null) {
return 0;
} else {
return buttons.size();
}
}
}
=2=
THE END |