java.lang.Object
javax.swing.DefaultButtonModel
- All Implemented Interfaces:
- ItemSelectable,- Serializable,- ButtonModel
- Direct Known Subclasses:
- 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 JavaBeans
 has been added to the java.beans package.
 Please see XMLEncoder.
- Since:
- 1.2
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected StringThe action command string fired by the button.static final intIdentifies the "armed" bit in the bitmask, which indicates partial commitment towards choosing/triggering the button.protected ChangeEventOnly oneChangeEventis needed per button model instance since the event's only state is the source property.static final intIdentifies the "enabled" bit in the bitmask, which indicates that the button can be selected by an input device (such as a mouse pointer).protected ButtonGroupThe button group that the button belongs to.protected EventListenerListStores the listeners on this model.protected intThe button's mnemonic.static final intIdentifies the "pressed" bit in the bitmask, which indicates that the button is pressed.static final intIdentifies the "rollover" bit in the bitmask, which indicates that the mouse is over the button.static final intIdentifies the "selected" bit in the bitmask, which indicates that the button has been selected.protected intThe bitmask used to store the state of the button.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdds anActionListenerto the model.voidAdds aChangeListenerto the model.voidAdds anItemListenerto the model.protected voidNotifies all listeners that have registered interest for notification on this event type.protected voidNotifies all listeners that have registered interest for notification on this event type.protected voidNotifies all listeners that have registered interest for notification on this event type.Returns the action command string for the button.Returns an array of all the action listeners registered on thisDefaultButtonModel.Returns an array of all the change listeners registered on thisDefaultButtonModel.getGroup()Returns the group that the button belongs to.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.intGets the keyboard mnemonic for the button.Object[]Overridden to returnnull.booleanisArmed()Indicates partial commitment towards triggering the button.booleanIndicates if the button can be selected or triggered by an input device, such as a mouse pointer.booleanIndicates if the button is pressed.booleanIndicates that the mouse is over the button.booleanIndicates if the button has been selected.voidRemoves anActionListenerfrom the model.voidRemoves aChangeListenerfrom the model.voidRemoves anItemListenerfrom the model.voidsetActionCommand(String actionCommand) Sets the action command string that gets sent as part of theActionEventwhen the button is triggered.voidsetArmed(boolean b) Marks the button as armed or unarmed.voidsetEnabled(boolean b) Enables or disables the button.voidsetGroup(ButtonGroup group) Identifies the group the button belongs to -- needed for radio buttons, which are mutually exclusive within their group.voidsetMnemonic(int key) Sets the keyboard mnemonic (shortcut key or accelerator key) for the button.voidsetPressed(boolean b) Sets the button to pressed or unpressed.voidsetRollover(boolean b) Sets or clears the button's rollover statevoidsetSelected(boolean b) Selects or deselects the button.
- 
Field Details- 
stateMaskprotected int stateMaskThe bitmask used to store the state of the button.
- 
actionCommandThe action command string fired by the button.
- 
groupThe button group that the button belongs to.
- 
mnemonicprotected int mnemonicThe button's mnemonic.
- 
changeEventOnly oneChangeEventis needed per button model instance since the event's only state is the source property. The source of events generated is always "this".
- 
listenerListStores the listeners on this model.
- 
ARMEDpublic static final int ARMEDIdentifies the "armed" bit in the bitmask, which indicates partial commitment towards choosing/triggering the button.- See Also:
 
- 
SELECTEDpublic static final int SELECTEDIdentifies 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:
 
- 
PRESSEDpublic static final int PRESSEDIdentifies the "pressed" bit in the bitmask, which indicates that the button is pressed.- See Also:
 
- 
ENABLEDpublic static final int ENABLEDIdentifies 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:
 
- 
ROLLOVERpublic static final int ROLLOVERIdentifies the "rollover" bit in the bitmask, which indicates that the mouse is over the button.- See Also:
 
 
- 
- 
Constructor Details- 
DefaultButtonModelpublic DefaultButtonModel()Constructs aDefaultButtonModel.
 
- 
- 
Method Details- 
setActionCommandSets the action command string that gets sent as part of theActionEventwhen the button is triggered.- Specified by:
- setActionCommandin interface- ButtonModel
- Parameters:
- actionCommand- the- Stringthat identifies the generated event
- See Also:
 
- 
getActionCommandReturns the action command string for the button.- Specified by:
- getActionCommandin interface- ButtonModel
- Returns:
- the Stringthat identifies the generated event
- See Also:
 
- 
isArmedpublic boolean isArmed()Indicates partial commitment towards triggering the button.- Specified by:
- isArmedin interface- ButtonModel
- Returns:
- trueif the button is armed, and ready to be triggered
- See Also:
 
- 
isSelectedpublic boolean isSelected()Indicates if the button has been selected. Only needed for certain types of buttons - such as radio buttons and check boxes.- Specified by:
- isSelectedin interface- ButtonModel
- Returns:
- trueif the button is selected
 
- 
isEnabledpublic boolean isEnabled()Indicates if the button can be selected or triggered by an input device, such as a mouse pointer.- Specified by:
- isEnabledin interface- ButtonModel
- Returns:
- trueif the button is enabled
 
- 
isPressedpublic boolean isPressed()Indicates if the button is pressed.- Specified by:
- isPressedin interface- ButtonModel
- Returns:
- trueif the button is pressed
 
- 
isRolloverpublic boolean isRollover()Indicates that the mouse is over the button.- Specified by:
- isRolloverin interface- ButtonModel
- Returns:
- trueif the mouse is over the button
 
- 
setArmedpublic void setArmed(boolean b) Marks the button as armed or unarmed.- Specified by:
- setArmedin interface- ButtonModel
- Parameters:
- b- whether or not the button should be armed
 
- 
setEnabledpublic void setEnabled(boolean b) Enables or disables the button.- Specified by:
- setEnabledin interface- ButtonModel
- Parameters:
- b- whether or not the button should be enabled
- See Also:
 
- 
setSelectedpublic void setSelected(boolean b) Selects or deselects the button.- Specified by:
- setSelectedin interface- ButtonModel
- Parameters:
- b-- trueselects the button,- falsedeselects the button
 
- 
setPressedpublic void setPressed(boolean b) Sets the button to pressed or unpressed.- Specified by:
- setPressedin interface- ButtonModel
- Parameters:
- b- whether or not the button should be pressed
- See Also:
 
- 
setRolloverpublic void setRollover(boolean b) Sets or clears the button's rollover state- Specified by:
- setRolloverin interface- ButtonModel
- Parameters:
- b- whether or not the button is in the rollover state
- See Also:
 
- 
setMnemonicpublic void setMnemonic(int key) Sets the keyboard mnemonic (shortcut key or accelerator key) for the button.- Specified by:
- setMnemonicin interface- ButtonModel
- Parameters:
- key- an int specifying the accelerator key
 
- 
getMnemonicpublic int getMnemonic()Gets the keyboard mnemonic for the button.- Specified by:
- getMnemonicin interface- ButtonModel
- Returns:
- an int specifying the accelerator key
- See Also:
 
- 
addChangeListenerAdds aChangeListenerto the model.- Specified by:
- addChangeListenerin interface- ButtonModel
- Parameters:
- l- the listener to add
 
- 
removeChangeListenerRemoves aChangeListenerfrom the model.- Specified by:
- removeChangeListenerin interface- ButtonModel
- Parameters:
- l- the listener to remove
 
- 
getChangeListenersReturns 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:
 
- 
fireStateChangedprotected void fireStateChanged()Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.- See Also:
 
- 
addActionListenerAdds anActionListenerto the model.- Specified by:
- addActionListenerin interface- ButtonModel
- Parameters:
- l- the listener to add
 
- 
removeActionListenerRemoves anActionListenerfrom the model.- Specified by:
- removeActionListenerin interface- ButtonModel
- Parameters:
- l- the listener to remove
 
- 
getActionListenersReturns 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:
 
- 
fireActionPerformedNotifies all listeners that have registered interest for notification on this event type.- Parameters:
- e- the- ActionEventto deliver to listeners
- See Also:
 
- 
addItemListenerAdds anItemListenerto the model.- Specified by:
- addItemListenerin interface- ButtonModel
- Specified by:
- addItemListenerin interface- ItemSelectable
- Parameters:
- l- the listener to add
- See Also:
 
- 
removeItemListenerRemoves anItemListenerfrom the model.- Specified by:
- removeItemListenerin interface- ButtonModel
- Specified by:
- removeItemListenerin interface- ItemSelectable
- Parameters:
- l- the listener to remove
- See Also:
 
- 
getItemListenersReturns 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:
 
- 
fireItemStateChangedNotifies all listeners that have registered interest for notification on this event type.- Parameters:
- e- the- ItemEventto deliver to listeners
- See Also:
 
- 
getListenersReturns 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:
 
- 
getSelectedObjectsOverridden to returnnull.- Specified by:
- getSelectedObjectsin interface- ItemSelectable
- Returns:
- the list of selected objects, or null
 
- 
setGroupIdentifies the group the button belongs to -- needed for radio buttons, which are mutually exclusive within their group.- Specified by:
- setGroupin interface- ButtonModel
- Parameters:
- group- the- ButtonGroupthe button belongs to
 
- 
getGroupReturns 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
 
 
-