public class javax.swing
DefaultButtonModel


Hide details Login
Java SE 6
  
Implements: ButtonModel, Serializable
Extended by: JToggleButton.ToggleButtonModel

The default implementation of a Button component's data model.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see java.beans.XMLEncoder.
version1.49 05/25/06


Fields
protected int stateMask
The bitmask used to store the state of the button.
protected String actionCommand
The action command string fired by the button.
protected ButtonGroup group
The button group that the button belongs to.
protected int mnemonic
The button's mnemonic.
protected ChangeEvent changeEvent
Only one ChangeEvent is needed per button model instance since the event's only state is the source property. The source of events generated is always "this".
protected EventListenerList listenerList
Stores the listeners on this model.
final public static int ARMED
Identifies the "armed" bit in the bitmask, which indicates partial commitment towards choosing/triggering the button.
final public static int SELECTED
Identifies the "selected" bit in the bitmask, which indicates that the button has been selected. Only needed for certain types of buttons - such as radio button or check box.
final public static int PRESSED
Identifies the "pressed" bit in the bitmask, which indicates that the button is pressed.
final public static int ENABLED
Identifies the "enabled" bit in the bitmask, which indicates that the button can be selected by an input device (such as a mouse pointer).
final public static int ROLLOVER
Identifies the "rollover" bit in the bitmask, which indicates that the mouse is over the button.

Constructors
public DefaultButtonModel()
Constructs a DefaultButtonModel.

Methods
public void addActionListener(ActionListener l)
Adds an ActionListener to the model.
public void addChangeListener(ChangeListener l)
Adds a ChangeListener to the model.
public void addItemListener(ItemListener l)
Adds an ItemListener to the model.
protected void fireActionPerformed(ActionEvent e)
Notifies all listeners that have registered interest for notification on this event type.
ethe ActionEvent to deliver to listeners
See also javax.swing.event.EventListenerList
protected void fireItemStateChanged(ItemEvent e)
Notifies all listeners that have registered interest for notification on this event type.
ethe ItemEvent to deliver to listeners
See also javax.swing.event.EventListenerList
protected void fireStateChanged()
Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.
See also javax.swing.event.EventListenerList
public void removeActionListener(ActionListener l)
Removes an ActionListener from the model.
public void removeChangeListener(ChangeListener l)
Removes a ChangeListener from the model.
public void removeItemListener(ItemListener l)
Removes an ItemListener from the model.

Properties
public void setActionCommand(String actionCommand)
Sets the action command string that gets sent as part of the ActionEvent when the button is triggered.
public String getActionCommand()
Returns the action command string for the button.
public ActionListener[] getActionListeners()
Returns an array of all the action listeners registered on this DefaultButtonModel.
returnall of this model's ActionListeners or an empty array if no action listeners are currently registered
since1.4
See also addActionListener, removeActionListener
public void setArmed(boolean b)
Marks the button as armed or unarmed.
public boolean isArmed()
Indicates partial commitment towards triggering the button.
public ChangeListener[] getChangeListeners()
Returns an array of all the change listeners registered on this DefaultButtonModel.
returnall of this model's ChangeListeners or an empty array if no change listeners are currently registered
since1.4
See also addChangeListener, removeChangeListener
public void setEnabled(boolean b)
Enables or disables the button.
public boolean isEnabled()
Indicates if the button can be selected or triggered by an input device, such as a mouse pointer.
public void setGroup(ButtonGroup group)
Identifies the group the button belongs to -- needed for radio buttons, which are mutually exclusive within their group.
public ButtonGroup getGroup()
Returns the group that the button belongs to. Normally used with radio buttons, which are mutually exclusive within their group.
returnthe ButtonGroup that the button belongs to
since1.3
public ItemListener[] getItemListeners()
Returns an array of all the item listeners registered on this DefaultButtonModel.
returnall of this model's ItemListeners or an empty array if no item listeners are currently registered
since1.4
See also addItemListener, removeItemListener
public EventListener[]<T> getListeners(Class listenerType)
Returns an array of all the objects currently registered as FooListeners upon this model. FooListeners are registered using the addFooListener method.

You can specify the listenerType argument with a class literal, such as FooListener.class. For example, you can query a DefaultButtonModel instance m for its action listeners with the following code:

ActionListener[] als = (ActionListener[])(m.getListeners(ActionListener.class));
If no such listeners exist, this method returns an empty array.
listenerTypethe type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
returnan array of all objects registered as FooListeners on this model, or an empty array if no such listeners have been added
ThrowsClassCastException: if listenerType doesn't specify a class or interface that implements java.util.EventListener
since1.3
See also getActionListeners, getChangeListeners, getItemListeners
public void setMnemonic(int key)
Sets the keyboard mnemonic (shortcut key or accelerator key) for the button.
public int getMnemonic()
Gets the keyboard mnemonic for the button.
public void setPressed(boolean b)
Sets the button to pressed or unpressed.
public boolean isPressed()
Indicates if the button is pressed.
public void setRollover(boolean b)
Sets or clears the button's rollover state
public boolean isRollover()
Indicates that the mouse is over the button.
public void setSelected(boolean b)
Selects or deselects the button.
public boolean isSelected()
Indicates if the button has been selected. Only needed for certain types of buttons - such as radio buttons and check boxes.
public Object[] getSelectedObjects()
Overridden to return null.