- java.lang.Object
- 
- javax.swing.DefaultButtonModel
 
- 
- All Implemented Interfaces:
- ItemSelectable,- Serializable,- ButtonModel
 - Direct Known Subclasses:
- JToggleButton.ToggleButtonModel
 
 public class DefaultButtonModel extends Object implements ButtonModel, Serializable The default implementation of aButtoncomponent'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.beanspackage. Please seeXMLEncoder.- Since:
- 1.2
- See Also:
- Serialized Form
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected StringactionCommandThe action command string fired by the button.static intARMEDIdentifies the "armed" bit in the bitmask, which indicates partial commitment towards choosing/triggering the button.protected ChangeEventchangeEventOnly oneChangeEventis needed per button model instance since the event's only state is the source property.static intENABLEDIdentifies the "enabled" bit in the bitmask, which indicates that the button can be selected by an input device (such as a mouse pointer).protected ButtonGroupgroupThe button group that the button belongs to.protected EventListenerListlistenerListStores the listeners on this model.protected intmnemonicThe button's mnemonic.static intPRESSEDIdentifies the "pressed" bit in the bitmask, which indicates that the button is pressed.static intROLLOVERIdentifies the "rollover" bit in the bitmask, which indicates that the mouse is over the button.static intSELECTEDIdentifies the "selected" bit in the bitmask, which indicates that the button has been selected.protected intstateMaskThe bitmask used to store the state of the button.
 - 
Constructor SummaryConstructors Constructor Description DefaultButtonModel()Constructs aDefaultButtonModel.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidfireActionPerformed(ActionEvent e)Notifies all listeners that have registered interest for notification on this event type.protected voidfireItemStateChanged(ItemEvent e)Notifies all listeners that have registered interest for notification on this event type.protected voidfireStateChanged()Notifies all listeners that have registered interest for notification on this event type.ActionListener[]getActionListeners()Returns an array of all the action listeners registered on thisDefaultButtonModel.ChangeListener[]getChangeListeners()Returns an array of all the change listeners registered on thisDefaultButtonModel.ButtonGroupgetGroup()Returns the group that the button belongs to.ItemListener[]getItemListeners()Returns an array of all the item listeners registered on thisDefaultButtonModel.<T extends EventListener>
 T[]getListeners(Class<T> listenerType)Returns an array of all the objects currently registered asFooListeners upon this model.Object[]getSelectedObjects()Overridden to returnnull.- 
Methods declared in class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods declared in interface javax.swing.ButtonModeladdActionListener, addChangeListener, addItemListener, getActionCommand, getMnemonic, isArmed, isEnabled, isPressed, isRollover, isSelected, removeActionListener, removeChangeListener, removeItemListener, setActionCommand, setArmed, setEnabled, setGroup, setMnemonic, setPressed, setRollover, setSelected
 
- 
 
- 
- 
- 
Field Detail- 
stateMaskprotected int stateMask The bitmask used to store the state of the button.
 - 
actionCommandprotected String actionCommand The action command string fired by the button.
 - 
groupprotected ButtonGroup group The button group that the button belongs to.
 - 
mnemonicprotected int mnemonic The button's mnemonic.
 - 
changeEventprotected transient ChangeEvent changeEvent Only oneChangeEventis needed per button model instance since the event's only state is the source property. The source of events generated is always "this".
 - 
listenerListprotected EventListenerList listenerList Stores the listeners on this model.
 - 
ARMEDpublic static final int ARMED Identifies the "armed" bit in the bitmask, which indicates partial commitment towards choosing/triggering the button.- See Also:
- Constant Field Values
 
 - 
SELECTEDpublic 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.- See Also:
- Constant Field Values
 
 - 
PRESSEDpublic static final int PRESSED Identifies the "pressed" bit in the bitmask, which indicates that the button is pressed.- See Also:
- Constant Field Values
 
 - 
ENABLEDpublic 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).- See Also:
- Constant Field Values
 
 - 
ROLLOVERpublic static final int ROLLOVER Identifies the "rollover" bit in the bitmask, which indicates that the mouse is over the button.- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getChangeListenerspublic ChangeListener[] getChangeListeners() Returns an array of all the change listeners registered on thisDefaultButtonModel.- Returns:
- all of this model's ChangeListeners or an empty array if no change listeners are currently registered
- Since:
- 1.4
- See Also:
- ButtonModel.addChangeListener(javax.swing.event.ChangeListener),- ButtonModel.removeChangeListener(javax.swing.event.ChangeListener)
 
 - 
fireStateChangedprotected void fireStateChanged() Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.- See Also:
- EventListenerList
 
 - 
getActionListenerspublic ActionListener[] getActionListeners() Returns an array of all the action listeners registered on thisDefaultButtonModel.- Returns:
- all of this model's ActionListeners or an empty array if no action listeners are currently registered
- Since:
- 1.4
- See Also:
- ButtonModel.addActionListener(java.awt.event.ActionListener),- ButtonModel.removeActionListener(java.awt.event.ActionListener)
 
 - 
fireActionPerformedprotected void fireActionPerformed(ActionEvent e) Notifies all listeners that have registered interest for notification on this event type.- Parameters:
- e- the- ActionEventto deliver to listeners
- See Also:
- EventListenerList
 
 - 
getItemListenerspublic ItemListener[] getItemListeners() Returns an array of all the item listeners registered on thisDefaultButtonModel.- Returns:
- all of this model's ItemListeners or an empty array if no item listeners are currently registered
- Since:
- 1.4
- See Also:
- ButtonModel.addItemListener(java.awt.event.ItemListener),- ButtonModel.removeItemListener(java.awt.event.ItemListener)
 
 - 
fireItemStateChangedprotected void fireItemStateChanged(ItemEvent e) Notifies all listeners that have registered interest for notification on this event type.- Parameters:
- e- the- ItemEventto deliver to listeners
- See Also:
- EventListenerList
 
 - 
getListenerspublic <T extends EventListener> T[] getListeners(Class<T> listenerType) Returns an array of all the objects currently registered asFooListeners upon this model.FooListeners are registered using theaddFooListenermethod.You can specify the listenerTypeargument with a class literal, such asFooListener.class. For example, you can query aDefaultButtonModelinstancemfor 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.- Type Parameters:
- T- the type of requested listeners
- Parameters:
- listenerType- the type of listeners requested; this parameter should specify an interface that descends from- java.util.EventListener
- Returns:
- an array of all objects registered as
          FooListeners on this model, or an empty array if no such listeners have been added
- Throws:
- ClassCastException- if- listenerTypedoesn't specify a class or interface that implements- java.util.EventListener
- Since:
- 1.3
- See Also:
- getActionListeners(),- getChangeListeners(),- getItemListeners()
 
 - 
getSelectedObjectspublic Object[] getSelectedObjects() Overridden to returnnull.- Specified by:
- getSelectedObjectsin interface- ItemSelectable
- Returns:
- the list of selected objects, or null
 
 - 
getGrouppublic ButtonGroup getGroup() Returns the group that the button belongs to. Normally used with radio buttons, which are mutually exclusive within their group.- Specified by:
- getGroupin interface- ButtonModel
- Returns:
- the ButtonGroupthat the button belongs to
- Since:
- 1.3
 
 
- 
 
-