FileDocCategorySizeDatePackage
ButtonModel.javaAPI DocJava SE 5 API5688Fri Aug 26 14:57:52 BST 2005javax.swing

ButtonModel

public interface ButtonModel implements 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 {@link #setSelected} when a mouse click occurs over a check box or radio button. It will invoke {@link #setArmed} when the mouse is pressed over a regular button and invoke {@link #setPressed} 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".
version
1.26 12/19/03
author
Jeff Dinkins

Fields Summary
Constructors Summary
Methods Summary
public voidaddActionListener(java.awt.event.ActionListener l)
Adds an ActionListener to the button.

param
l the listener to add

public voidaddChangeListener(javax.swing.event.ChangeListener l)
Adds a ChangeListener to the button.

param
l the listener to add

public voidaddItemListener(java.awt.event.ItemListener l)
Adds an ItemListener to the button.

param
l the listener to add

public java.lang.StringgetActionCommand()
Returns the action command for this button.

return
the String that identifies the generated event
see
#setActionCommand

public intgetMnemonic()
Gets the keyboard mnemonic for this model

return
an int specifying the accelerator key
see
#setMnemonic

public booleanisArmed()
Indicates partial commitment towards pressing the button.

return
true if the button is armed, and ready to be pressed
see
#setArmed

public booleanisEnabled()
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".)

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

public booleanisPressed()
Indicates if button has been pressed.

return
true if the button has been pressed

public booleanisRollover()
Indicates that the mouse is over the button.

return
true if the mouse is over the button

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

return
true if the button is selected

public voidremoveActionListener(java.awt.event.ActionListener l)
Removes an ActionListener from the button.

param
l the listener to remove

public voidremoveChangeListener(javax.swing.event.ChangeListener l)
Removes a ChangeListener from the button.

param
l the listener to remove

public voidremoveItemListener(java.awt.event.ItemListener l)
Removes an ItemListener from the button.

param
l the listener to remove

public voidsetActionCommand(java.lang.String s)
Sets the actionCommand string that gets sent as part of the event when the button is pressed.

param
s the String that identifies the generated event

public voidsetArmed(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.

param
b true to arm the button so it can be selected

public voidsetEnabled(boolean b)
Enables or disables the button.

param
b true to enable the button
see
#isEnabled

public voidsetGroup(javax.swing.ButtonGroup group)
Identifies the group this button belongs to -- needed for radio buttons, which are mutually exclusive within their group.

param
group the ButtonGroup this button belongs to

public voidsetMnemonic(int key)
Sets the keyboard mnemonic (shortcut key or accelerator key) for this button.

param
key an int specifying the accelerator key

public voidsetPressed(boolean b)
Sets the button to pressed or unpressed.

param
b true to set the button to "pressed"
see
#isPressed

public voidsetRollover(boolean b)
Sets or clears the button's rollover state

param
b true to turn on rollover
see
#isRollover

public voidsetSelected(boolean b)
Selects or deselects the button.

param
b true selects the button, false deselects the button.