Packageorg.aswing
Classpublic class ButtonGroup

This class is used to create a multiple-exclusion scope for a set of buttons. Creating a set of buttons with the same ButtonGroup object means that turning "on" one of those buttons turns off all other buttons in the group.

A ButtonGroup 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.

Initially, all buttons in the group are unselected. Once any button is selected, one button is always selected in the group. There is no way to turn a button programmatically to "off", in order to clear the button group. To give the appearance of "none selected", add an invisible radio button to the group and then programmatically select that button to turn off all the displayed radio buttons. For example, a normal button with the label "none" could be wired to select the invisible radio button.



Protected Properties
 PropertyDefined by
  buttons : Array
ButtonGroup
Public Methods
 MethodDefined by
  
Creates a new ButtonGroup.
ButtonGroup
  
Adds the button to the group.
ButtonGroup
  
appendAll(... buttons):void
Appends all buttons into this group.
ButtonGroup
  
Returns whether the group contains the button.
ButtonGroup
  
getButtonCount():Number
Returns the number of buttons in the group.
ButtonGroup
  
getElements():Array
Returns all the buttons that are participating in this group.
ButtonGroup
  
Return the first selected button, if none, return null.
ButtonGroup
  
Returns the model of the selected button.
ButtonGroup
  
groupButtons(... buttons):ButtonGroup
[static] Create a button group and append the buttons in, then return the group.
ButtonGroup
  
Returns whether a ButtonModel is selected.
ButtonGroup
  
Removes the button from the group.
ButtonGroup
  
setSelected(m:ButtonModel, b:Boolean):void
Sets the selected value for the ButtonModel.
ButtonGroup
Property detail
buttonsproperty
protected var buttons:Array
Constructor detail
ButtonGroup()constructor
public function ButtonGroup()

Creates a new ButtonGroup.

Method detail
append()method
public function append(b:AbstractButton):void

Adds the button to the group.

Parameters
b:AbstractButton — the button to be added
appendAll()method 
public function appendAll(... buttons):void

Appends all buttons into this group.

Parameters
... buttons
contains()method 
public function contains(b:AbstractButton):Boolean

Returns whether the group contains the button.

Parameters
b:AbstractButton

Returns
Boolean — true if the group contains the button, false otherwise
getButtonCount()method 
public function getButtonCount():Number

Returns the number of buttons in the group.

Returns
Number — the button count
getElements()method 
public function getElements():Array

Returns all the buttons that are participating in this group.

Returns
Array — an Array of the buttons in this group
getSelectedButton()method 
public function getSelectedButton():AbstractButton

Return the first selected button, if none, return null.

Returns
AbstractButton
getSelection()method 
public function getSelection():ButtonModel

Returns the model of the selected button.

Returns
ButtonModel — the selected button model
groupButtons()method 
public static function groupButtons(... buttons):ButtonGroup

Create a button group and append the buttons in, then return the group.

Parameters
... buttons

Returns
ButtonGroup — the button group.
isSelected()method 
public function isSelected(m:ButtonModel):Boolean

Returns whether a ButtonModel is selected.

Parameters
m:ButtonModel

Returns
Booleantrue if the button is selected, otherwise returns false
remove()method 
public function remove(b:AbstractButton):void

Removes the button from the group.

Parameters
b:AbstractButton — the button to be removed
setSelected()method 
public function setSelected(m:ButtonModel, b:Boolean):void

Sets the selected value for the ButtonModel. Only one button in the group may be selected at a time.

Parameters
m:ButtonModel — the ButtonModel
 
b:Booleantrue if this button is to be selected, otherwise false