public class DefaultButtonModel extends Object implements ButtonModel, Serializable
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 JavaBeans™ has been added to the java.beans package. Please see XMLEncoder.
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 transient 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.
public static final int ARMED
Identifies the "armed" bit in the bitmask, which indicates partial commitment towards choosing/triggering the button.
public static final 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.
public static final int PRESSED
Identifies the "pressed" bit in the bitmask, which indicates that the button is pressed.
public static final 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).
public static final int ROLLOVER
Identifies the "rollover" bit in the bitmask, which indicates that the mouse is over the button.
public DefaultButtonModel()
Constructs a DefaultButtonModel.
public void setActionCommand(String actionCommand)
Sets the action command string that gets sent as part of the ActionEvent when the button is triggered.
setActionCommand in interface ButtonModel
actionCommand - the String that identifies the generated eventButtonModel.getActionCommand(), ActionEvent.getActionCommand()
public String getActionCommand()
Returns the action command string for the button.
getActionCommand in interface ButtonModel
String that identifies the generated eventButtonModel.setActionCommand(java.lang.String)public boolean isArmed()
Indicates partial commitment towards triggering the button.
isArmed in interface ButtonModel
true if the button is armed, and ready to be triggeredButtonModel.setArmed(boolean)public boolean isSelected()
Indicates if the button has been selected. Only needed for certain types of buttons - such as radio buttons and check boxes.
isSelected in interface ButtonModel
true if the button is selectedpublic boolean isEnabled()
Indicates if the button can be selected or triggered by an input device, such as a mouse pointer.
isEnabled in interface ButtonModel
true if the button is enabledpublic boolean isPressed()
Indicates if the button is pressed.
isPressed in interface ButtonModel
true if the button is pressedpublic boolean isRollover()
Indicates that the mouse is over the button.
isRollover in interface ButtonModel
true if the mouse is over the buttonpublic void setArmed(boolean b)
Marks the button as armed or unarmed.
setArmed in interface ButtonModel
b - whether or not the button should be armedpublic void setEnabled(boolean b)
Enables or disables the button.
setEnabled in interface ButtonModel
b - whether or not the button should be enabledButtonModel.isEnabled()public void setSelected(boolean b)
Selects or deselects the button.
setSelected in interface ButtonModel
b - true selects the button, false deselects the buttonpublic void setPressed(boolean b)
Sets the button to pressed or unpressed.
setPressed in interface ButtonModel
b - whether or not the button should be pressedButtonModel.isPressed()public void setRollover(boolean b)
Sets or clears the button's rollover state
setRollover in interface ButtonModel
b - whether or not the button is in the rollover stateButtonModel.isRollover()public void setMnemonic(int key)
Sets the keyboard mnemonic (shortcut key or accelerator key) for the button.
setMnemonic in interface ButtonModel
key - an int specifying the accelerator keypublic int getMnemonic()
Gets the keyboard mnemonic for the button.
getMnemonic in interface ButtonModel
ButtonModel.setMnemonic(int)public void addChangeListener(ChangeListener l)
Adds a ChangeListener to the model.
addChangeListener in interface ButtonModel
l - the listener to addpublic void removeChangeListener(ChangeListener l)
Removes a ChangeListener from the model.
removeChangeListener in interface ButtonModel
l - the listener to removepublic ChangeListener[] getChangeListeners()
Returns an array of all the change listeners registered on this DefaultButtonModel.
ChangeListeners or an empty array if no change listeners are currently registeredaddChangeListener(javax.swing.event.ChangeListener), removeChangeListener(javax.swing.event.ChangeListener)
protected void fireStateChanged()
Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.
EventListenerListpublic void addActionListener(ActionListener l)
Adds an ActionListener to the model.
addActionListener in interface ButtonModel
l - the listener to addpublic void removeActionListener(ActionListener l)
Removes an ActionListener from the model.
removeActionListener in interface ButtonModel
l - the listener to removepublic ActionListener[] getActionListeners()
Returns an array of all the action listeners registered on this DefaultButtonModel.
ActionListeners or an empty array if no action listeners are currently registeredaddActionListener(java.awt.event.ActionListener), removeActionListener(java.awt.event.ActionListener)
protected void fireActionPerformed(ActionEvent e)
Notifies all listeners that have registered interest for notification on this event type.
e - the ActionEvent to deliver to listenersEventListenerListpublic void addItemListener(ItemListener l)
Adds an ItemListener to the model.
addItemListener in interface ItemSelectable
addItemListener in interface ButtonModel
l - the listener to addItemEventpublic void removeItemListener(ItemListener l)
Removes an ItemListener from the model.
removeItemListener in interface ItemSelectable
removeItemListener in interface ButtonModel
l - the listener to removeItemEventpublic ItemListener[] getItemListeners()
Returns an array of all the item listeners registered on this DefaultButtonModel.
ItemListeners or an empty array if no item listeners are currently registeredaddItemListener(java.awt.event.ItemListener), removeItemListener(java.awt.event.ItemListener)
protected void fireItemStateChanged(ItemEvent e)
Notifies all listeners that have registered interest for notification on this event type.
e - the ItemEvent to deliver to listenersEventListenerListpublic <T extends EventListener> T[] getListeners(Class<T> 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.
listenerType - the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
FooListeners on this model, or an empty array if no such listeners have been addedClassCastException - if listenerType doesn't specify a class or interface that implements java.util.EventListener
getActionListeners(), getChangeListeners(), getItemListeners()
public Object[] getSelectedObjects()
Overridden to return null.
getSelectedObjects in interface ItemSelectable
public void setGroup(ButtonGroup group)
Identifies the group the button belongs to -- needed for radio buttons, which are mutually exclusive within their group.
setGroup in interface ButtonModel
group - the ButtonGroup the button belongs topublic ButtonGroup getGroup()
Returns the group that the button belongs to. Normally used with radio buttons, which are mutually exclusive within their group.
ButtonGroup that the button belongs to
© 1993–2017, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.