javax.swing
Interface ButtonModel

All Superinterfaces:
ItemSelectable sample code for java.awt.ItemSelectable definition code for java.awt.ItemSelectable
All Known Implementing Classes:
DefaultButtonModel sample code for javax.swing.DefaultButtonModel definition code for javax.swing.DefaultButtonModel , JToggleButton.ToggleButtonModel sample code for javax.swing.JToggleButton.ToggleButtonModel definition code for javax.swing.JToggleButton.ToggleButtonModel

public interface ButtonModel
extends ItemSelectable sample code for java.awt.ItemSelectable definition code for java.awt.ItemSelectable

State Model for buttons. This model is used for check boxes and radio buttons, which are special kinds of buttons, as well as for normal buttons. For check boxes and radio buttons, pressing the mouse selects the button. For normal buttons, pressing the mouse "arms" the button. Releasing the mouse over the button then initiates a button press, firing its action event. Releasing the mouse elsewhere disarms the button.

In use, a UI will invoke setSelected(boolean) sample code for javax.swing.ButtonModel.setSelected(boolean) definition code for javax.swing.ButtonModel.setSelected(boolean) when a mouse click occurs over a check box or radio button. It will invoke setArmed(boolean) sample code for javax.swing.ButtonModel.setArmed(boolean) definition code for javax.swing.ButtonModel.setArmed(boolean) when the mouse is pressed over a regular button and invoke setPressed(boolean) sample code for javax.swing.ButtonModel.setPressed(boolean) definition code for javax.swing.ButtonModel.setPressed(boolean) when the mouse is released. If the mouse travels outside the button in the meantime, setArmed(false) will tell the button not to fire when it sees setPressed. (If the mouse travels back in, the button will be rearmed.)

Note:
A button is triggered when it is both "armed" and "pressed".


Method Summary
 void addActionListener sample code for javax.swing.ButtonModel.addActionListener(java.awt.event.ActionListener) definition code for javax.swing.ButtonModel.addActionListener(java.awt.event.ActionListener) (ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener  l)
          Adds an ActionListener to the button.
 void addChangeListener sample code for javax.swing.ButtonModel.addChangeListener(javax.swing.event.ChangeListener) definition code for javax.swing.ButtonModel.addChangeListener(javax.swing.event.ChangeListener) (ChangeListener sample code for javax.swing.event.ChangeListener definition code for javax.swing.event.ChangeListener  l)
          Adds a ChangeListener to the button.
 void addItemListener sample code for javax.swing.ButtonModel.addItemListener(java.awt.event.ItemListener) definition code for javax.swing.ButtonModel.addItemListener(java.awt.event.ItemListener) (ItemListener sample code for java.awt.event.ItemListener definition code for java.awt.event.ItemListener  l)
          Adds an ItemListener to the button.
 String sample code for java.lang.String definition code for java.lang.String getActionCommand sample code for javax.swing.ButtonModel.getActionCommand() definition code for javax.swing.ButtonModel.getActionCommand() ()
          Returns the action command for this button.
 int getMnemonic sample code for javax.swing.ButtonModel.getMnemonic() definition code for javax.swing.ButtonModel.getMnemonic() ()
          Gets the keyboard mnemonic for this model
 boolean isArmed sample code for javax.swing.ButtonModel.isArmed() definition code for javax.swing.ButtonModel.isArmed() ()
          Indicates partial commitment towards pressing the button.
 boolean isEnabled sample code for javax.swing.ButtonModel.isEnabled() definition code for javax.swing.ButtonModel.isEnabled() ()
          Indicates if the button can be selected or pressed by an input device (such as a mouse pointer).
 boolean isPressed sample code for javax.swing.ButtonModel.isPressed() definition code for javax.swing.ButtonModel.isPressed() ()
          Indicates if button has been pressed.
 boolean isRollover sample code for javax.swing.ButtonModel.isRollover() definition code for javax.swing.ButtonModel.isRollover() ()
          Indicates that the mouse is over the button.
 boolean isSelected sample code for javax.swing.ButtonModel.isSelected() definition code for javax.swing.ButtonModel.isSelected() ()
          Indicates if the button has been selected.
 void removeActionListener sample code for javax.swing.ButtonModel.removeActionListener(java.awt.event.ActionListener) definition code for javax.swing.ButtonModel.removeActionListener(java.awt.event.ActionListener) (ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener  l)
          Removes an ActionListener from the button.
 void removeChangeListener sample code for javax.swing.ButtonModel.removeChangeListener(javax.swing.event.ChangeListener) definition code for javax.swing.ButtonModel.removeChangeListener(javax.swing.event.ChangeListener) (ChangeListener sample code for javax.swing.event.ChangeListener definition code for javax.swing.event.ChangeListener  l)
          Removes a ChangeListener from the button.
 void removeItemListener sample code for javax.swing.ButtonModel.removeItemListener(java.awt.event.ItemListener) definition code for javax.swing.ButtonModel.removeItemListener(java.awt.event.ItemListener) (ItemListener sample code for java.awt.event.ItemListener definition code for java.awt.event.ItemListener  l)
          Removes an ItemListener from the button.
 void setActionCommand sample code for javax.swing.ButtonModel.setActionCommand(java.lang.String) definition code for javax.swing.ButtonModel.setActionCommand(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  s)
          Sets the actionCommand string that gets sent as part of the event when the button is pressed.
 void setArmed sample code for javax.swing.ButtonModel.setArmed(boolean) definition code for javax.swing.ButtonModel.setArmed(boolean) (boolean b)
          Marks the button as "armed".
 void setEnabled sample code for javax.swing.ButtonModel.setEnabled(boolean) definition code for javax.swing.ButtonModel.setEnabled(boolean) (boolean b)
          Enables or disables the button.
 void setGroup sample code for javax.swing.ButtonModel.setGroup(javax.swing.ButtonGroup) definition code for javax.swing.ButtonModel.setGroup(javax.swing.ButtonGroup) (ButtonGroup sample code for javax.swing.ButtonGroup definition code for javax.swing.ButtonGroup  group)
          Identifies the group this button belongs to -- needed for radio buttons, which are mutually exclusive within their group.
 void setMnemonic sample code for javax.swing.ButtonModel.setMnemonic(int) definition code for javax.swing.ButtonModel.setMnemonic(int) (int key)
          Sets the keyboard mnemonic (shortcut key or accelerator key) for this button.
 void setPressed sample code for javax.swing.ButtonModel.setPressed(boolean) definition code for javax.swing.ButtonModel.setPressed(boolean) (boolean b)
          Sets the button to pressed or unpressed.
 void setRollover sample code for javax.swing.ButtonModel.setRollover(boolean) definition code for javax.swing.ButtonModel.setRollover(boolean) (boolean b)
          Sets or clears the button's rollover state
 void setSelected sample code for javax.swing.ButtonModel.setSelected(boolean) definition code for javax.swing.ButtonModel.setSelected(boolean) (boolean b)
          Selects or deselects the button.
 
Methods inherited from interface java.awt.ItemSelectable sample code for java.awt.ItemSelectable definition code for java.awt.ItemSelectable
getSelectedObjects sample code for java.awt.ItemSelectable.getSelectedObjects() definition code for java.awt.ItemSelectable.getSelectedObjects()
 

Method Detail

isArmed sample code for javax.swing.ButtonModel.isArmed() definition code for javax.swing.ButtonModel.isArmed()

boolean isArmed()
Indicates partial commitment towards pressing the button.

Returns:
true if the button is armed, and ready to be pressed
See Also:
setArmed(boolean) sample code for javax.swing.ButtonModel.setArmed(boolean) definition code for javax.swing.ButtonModel.setArmed(boolean)

isSelected sample code for javax.swing.ButtonModel.isSelected() definition code for javax.swing.ButtonModel.isSelected()

boolean isSelected()
Indicates if the button has been selected. Only needed for certain types of buttons - such as radio buttons and check boxes.

Returns:
true if the button is selected

isEnabled sample code for javax.swing.ButtonModel.isEnabled() definition code for javax.swing.ButtonModel.isEnabled()

boolean isEnabled()
Indicates if the button can be selected or pressed by an input device (such as a mouse pointer). (Check boxes are selected, regular buttons are "pressed".)

Returns:
true if the button is enabled, and therefore selectable (or pressable)

isPressed sample code for javax.swing.ButtonModel.isPressed() definition code for javax.swing.ButtonModel.isPressed()

boolean isPressed()
Indicates if button has been pressed.

Returns:
true if the button has been pressed

isRollover sample code for javax.swing.ButtonModel.isRollover() definition code for javax.swing.ButtonModel.isRollover()

boolean isRollover()
Indicates that the mouse is over the button.

Returns:
true if the mouse is over the button

setArmed sample code for javax.swing.ButtonModel.setArmed(boolean) definition code for javax.swing.ButtonModel.setArmed(boolean)

void setArmed(boolean b)
Marks the button as "armed". If the mouse button is released while it is over this item, the button's action event fires. If the mouse button is released elsewhere, the event does not fire and the button is disarmed.

Parameters:
b - true to arm the button so it can be selected

setSelected sample code for javax.swing.ButtonModel.setSelected(boolean) definition code for javax.swing.ButtonModel.setSelected(boolean)

void setSelected(boolean b)
Selects or deselects the button.

Parameters:
b - true selects the button, false deselects the button.

setEnabled sample code for javax.swing.ButtonModel.setEnabled(boolean) definition code for javax.swing.ButtonModel.setEnabled(boolean)

void setEnabled(boolean b)
Enables or disables the button.

Parameters:
b - true to enable the button
See Also:
isEnabled() sample code for javax.swing.ButtonModel.isEnabled() definition code for javax.swing.ButtonModel.isEnabled()

setPressed sample code for javax.swing.ButtonModel.setPressed(boolean) definition code for javax.swing.ButtonModel.setPressed(boolean)

void setPressed(boolean b)
Sets the button to pressed or unpressed.

Parameters:
b - true to set the button to "pressed"
See Also:
isPressed() sample code for javax.swing.ButtonModel.isPressed() definition code for javax.swing.ButtonModel.isPressed()

setRollover sample code for javax.swing.ButtonModel.setRollover(boolean) definition code for javax.swing.ButtonModel.setRollover(boolean)

void setRollover(boolean b)
Sets or clears the button's rollover state

Parameters:
b - true to turn on rollover
See Also:
isRollover() sample code for javax.swing.ButtonModel.isRollover() definition code for javax.swing.ButtonModel.isRollover()

setMnemonic sample code for javax.swing.ButtonModel.setMnemonic(int) definition code for javax.swing.ButtonModel.setMnemonic(int)

void setMnemonic(int key)
Sets the keyboard mnemonic (shortcut key or accelerator key) for this button.

Parameters:
key - an int specifying the accelerator key

getMnemonic sample code for javax.swing.ButtonModel.getMnemonic() definition code for javax.swing.ButtonModel.getMnemonic()

int getMnemonic()
Gets the keyboard mnemonic for this model

Returns:
an int specifying the accelerator key
See Also:
setMnemonic(int) sample code for javax.swing.ButtonModel.setMnemonic(int) definition code for javax.swing.ButtonModel.setMnemonic(int)

setActionCommand sample code for javax.swing.ButtonModel.setActionCommand(java.lang.String) definition code for javax.swing.ButtonModel.setActionCommand(java.lang.String)

void setActionCommand(String sample code for java.lang.String definition code for java.lang.String  s)
Sets the actionCommand string that gets sent as part of the event when the button is pressed.

Parameters:
s - the String that identifies the generated event

getActionCommand sample code for javax.swing.ButtonModel.getActionCommand() definition code for javax.swing.ButtonModel.getActionCommand()

String sample code for java.lang.String definition code for java.lang.String  getActionCommand()
Returns the action command for this button.

Returns:
the String that identifies the generated event
See Also:
setActionCommand(java.lang.String) sample code for javax.swing.ButtonModel.setActionCommand(java.lang.String) definition code for javax.swing.ButtonModel.setActionCommand(java.lang.String)

setGroup sample code for javax.swing.ButtonModel.setGroup(javax.swing.ButtonGroup) definition code for javax.swing.ButtonModel.setGroup(javax.swing.ButtonGroup)

void setGroup(ButtonGroup sample code for javax.swing.ButtonGroup definition code for javax.swing.ButtonGroup  group)
Identifies the group this button belongs to -- needed for radio buttons, which are mutually exclusive within their group.

Parameters:
group - the ButtonGroup this button belongs to

addActionListener sample code for javax.swing.ButtonModel.addActionListener(java.awt.event.ActionListener) definition code for javax.swing.ButtonModel.addActionListener(java.awt.event.ActionListener)

void addActionListener(ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener  l)
Adds an ActionListener to the button.

Parameters:
l - the listener to add

removeActionListener sample code for javax.swing.ButtonModel.removeActionListener(java.awt.event.ActionListener) definition code for javax.swing.ButtonModel.removeActionListener(java.awt.event.ActionListener)

void removeActionListener(ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener  l)
Removes an ActionListener from the button.

Parameters:
l - the listener to remove

addItemListener sample code for javax.swing.ButtonModel.addItemListener(java.awt.event.ItemListener) definition code for javax.swing.ButtonModel.addItemListener(java.awt.event.ItemListener)

void addItemListener(ItemListener sample code for java.awt.event.ItemListener definition code for java.awt.event.ItemListener  l)
Adds an ItemListener to the button.

Specified by:
addItemListener sample code for java.awt.ItemSelectable.addItemListener(java.awt.event.ItemListener) definition code for java.awt.ItemSelectable.addItemListener(java.awt.event.ItemListener) in interface ItemSelectable sample code for java.awt.ItemSelectable definition code for java.awt.ItemSelectable
Parameters:
l - the listener to add
See Also:
ItemEvent sample code for java.awt.event.ItemEvent definition code for java.awt.event.ItemEvent

removeItemListener sample code for javax.swing.ButtonModel.removeItemListener(java.awt.event.ItemListener) definition code for javax.swing.ButtonModel.removeItemListener(java.awt.event.ItemListener)

void removeItemListener(ItemListener sample code for java.awt.event.ItemListener definition code for java.awt.event.ItemListener  l)
Removes an ItemListener from the button.

Specified by:
removeItemListener sample code for java.awt.ItemSelectable.removeItemListener(java.awt.event.ItemListener) definition code for java.awt.ItemSelectable.removeItemListener(java.awt.event.ItemListener) in interface ItemSelectable sample code for java.awt.ItemSelectable definition code for java.awt.ItemSelectable
Parameters:
l - the listener to remove
See Also:
ItemEvent sample code for java.awt.event.ItemEvent definition code for java.awt.event.ItemEvent

addChangeListener sample code for javax.swing.ButtonModel.addChangeListener(javax.swing.event.ChangeListener) definition code for javax.swing.ButtonModel.addChangeListener(javax.swing.event.ChangeListener)

void addChangeListener(ChangeListener sample code for javax.swing.event.ChangeListener definition code for javax.swing.event.ChangeListener  l)
Adds a ChangeListener to the button.

Parameters:
l - the listener to add

removeChangeListener sample code for javax.swing.ButtonModel.removeChangeListener(javax.swing.event.ChangeListener) definition code for javax.swing.ButtonModel.removeChangeListener(javax.swing.event.ChangeListener)

void removeChangeListener(ChangeListener sample code for javax.swing.event.ChangeListener definition code for javax.swing.event.ChangeListener  l)
Removes a ChangeListener from the button.

Parameters:
l - the listener to remove