Top Description Fields Constructors Methods
javax.swing

public Class DefaultButtonModel

extends Object
implements ButtonModel, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, javax.swing.ButtonModel, java.awt.ItemSelectable
Known Direct Subclasses
javax.swing.JToggleButton.ToggleButtonModel, javax.swing.plaf.synth.SynthComboBoxUI.ButtonHandler
Annotations
@SuppressWarnings:serial
Imports
java.awt.*, java.awt.event.*, java.awt.image.*, java.io.Serializable, java.util.EventListener, javax.swing.event.*

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 java.beans.XMLEncoder.

Author
Jeff Dinkins
Since
1.2

Field Summary

Modifier and TypeField and Description
protected String
actionCommand

The action command string fired by the button.

public static final int
ARMED

Identifies the "armed" bit in the bitmask, which indicates partial commitment towards choosing/triggering the button.

protected transient ChangeEvent
changeEvent

Only one ChangeEvent is needed per button model instance since the event's only state is the source property.

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).

protected ButtonGroup
group

The button group that the button belongs to.

protected EventListenerList
listenerList

Stores the listeners on this model.

protected int
mnemonic

The button's mnemonic.

public static final int
PRESSED

Identifies the "pressed" bit in the bitmask, which indicates that the button is pressed.

public static final int
ROLLOVER

Identifies the "rollover" bit in the bitmask, which indicates that the mouse is over the button.

public static final int
SELECTED

Identifies the "selected" bit in the bitmask, which indicates that the button has been selected.

protected int
stateMask

The bitmask used to store the state of the button.

Constructor Summary

AccessConstructor and Description
public
DefaultButtonModel()

Constructs a DefaultButtonModel.

Method Summary

Modifier and TypeMethod and Description
public void
addActionListener(ActionListener
the listener to add
l
)

Implements javax.swing.ButtonModel.addActionListener.

Adds an ActionListener to the model.
public void
addChangeListener(ChangeListener
the listener to add
l
)

Implements javax.swing.ButtonModel.addChangeListener.

Adds a ChangeListener to the model.
public void
addItemListener(ItemListener
the listener to add
l
)

Implements javax.swing.ButtonModel.addItemListener.

Adds an ItemListener to the model.
protected void
fireActionPerformed(ActionEvent
the ActionEvent to deliver to listeners
e
)

Notifies all listeners that have registered interest for notification on this event type.

protected void
fireItemStateChanged(ItemEvent
the ItemEvent to deliver to listeners
e
)

Notifies all listeners that have registered interest for notification on this event type.

protected void
fireStateChanged()

Notifies all listeners that have registered interest for notification on this event type.

public String
getActionCommand()

Implements javax.swing.ButtonModel.getActionCommand.

Returns the action command string for the button.
public ActionListener[]

Returns:

all of this model's ActionListeners or an empty array if no action listeners are currently registered
getActionListeners
()

Returns an array of all the action listeners registered on this DefaultButtonModel.

public ChangeListener[]

Returns:

all of this model's ChangeListeners or an empty array if no change listeners are currently registered
getChangeListeners
()

Returns an array of all the change listeners registered on this DefaultButtonModel.

public ButtonGroup

Returns:

the ButtonGroup that the button belongs to
getGroup
()

Overrides default javax.swing.ButtonModel.getGroup.

Returns the group that the button belongs to.
public ItemListener[]

Returns:

all of this model's ItemListeners or an empty array if no item listeners are currently registered
getItemListeners
()

Returns an array of all the item listeners registered on this DefaultButtonModel.

public <
the type of requested listeners
T extends EventListener
>
T[]

Returns:

an array of all objects registered as FooListeners on this model, or an empty array if no such listeners have been added
getListeners
(Class<T>
the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
listenerType
)

Returns an array of all the objects currently registered as FooListeners upon this model.

public int
getMnemonic()

Implements javax.swing.ButtonModel.getMnemonic.

Gets the keyboard mnemonic for the button.
public Object[]
getSelectedObjects()

Implements java.awt.ItemSelectable.getSelectedObjects.

Overridden to return null.
public boolean
isArmed()

Implements javax.swing.ButtonModel.isArmed.

Indicates partial commitment towards triggering the button.
public boolean
isEnabled()

Implements javax.swing.ButtonModel.isEnabled.

Indicates if the button can be selected or triggered by an input device, such as a mouse pointer.
pack-priv boolean
public boolean
isPressed()

Implements javax.swing.ButtonModel.isPressed.

Indicates if the button is pressed.
public boolean
isRollover()

Implements javax.swing.ButtonModel.isRollover.

Indicates that the mouse is over the button.
public boolean
isSelected()

Implements javax.swing.ButtonModel.isSelected.

Indicates if the button has been selected.
public void
removeActionListener(ActionListener
the listener to remove
l
)

Implements javax.swing.ButtonModel.removeActionListener.

Removes an ActionListener from the model.
public void
removeChangeListener(ChangeListener
the listener to remove
l
)

Implements javax.swing.ButtonModel.removeChangeListener.

Removes a ChangeListener from the model.
public void
removeItemListener(ItemListener
the listener to remove
l
)

Implements javax.swing.ButtonModel.removeItemListener.

Removes an ItemListener from the model.
public void
setActionCommand(String
the String that identifies the generated event
actionCommand
)

Implements javax.swing.ButtonModel.setActionCommand.

Sets the action command string that gets sent as part of the ActionEvent when the button is triggered.
public void
setArmed(boolean
whether or not the button should be armed
b
)

Implements javax.swing.ButtonModel.setArmed.

Marks the button as armed or unarmed.
public void
setEnabled(boolean
whether or not the button should be enabled
b
)

Implements javax.swing.ButtonModel.setEnabled.

Enables or disables the button.
public void
setGroup(ButtonGroup
the ButtonGroup the button belongs to
group
)

Implements javax.swing.ButtonModel.setGroup.

Identifies the group the button belongs to -- needed for radio buttons, which are mutually exclusive within their group.
pack-priv void
setMenuItem(boolean menuItem)

public void
setMnemonic(int
an int specifying the accelerator key
key
)

Implements javax.swing.ButtonModel.setMnemonic.

Sets the keyboard mnemonic (shortcut key or accelerator key) for the button.
public void
setPressed(boolean
whether or not the button should be pressed
b
)

Implements javax.swing.ButtonModel.setPressed.

Sets the button to pressed or unpressed.
public void
setRollover(boolean
whether or not the button is in the rollover state
b
)

Implements javax.swing.ButtonModel.setRollover.

Sets or clears the button's rollover state
public void
setSelected(boolean
true selects the button, false deselects the button
b
)

Implements javax.swing.ButtonModel.setSelected.

Selects or deselects the button.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actionCommandback to summary
protected String actionCommand

The action command string fired by the button.

ARMEDback to summary
public static final int ARMED

Identifies the "armed" bit in the bitmask, which indicates partial commitment towards choosing/triggering the button.

changeEventback to summary
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".

ENABLEDback to summary
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).

groupback to summary
protected ButtonGroup group

The button group that the button belongs to.

listenerListback to summary
protected EventListenerList listenerList

Stores the listeners on this model.

mnemonicback to summary
protected int mnemonic

The button's mnemonic.

PRESSEDback to summary
public static final int PRESSED

Identifies the "pressed" bit in the bitmask, which indicates that the button is pressed.

ROLLOVERback to summary
public static final int ROLLOVER

Identifies the "rollover" bit in the bitmask, which indicates that the mouse is over the button.

SELECTEDback to summary
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.

stateMaskback to summary
protected int stateMask

The bitmask used to store the state of the button.

Constructor Detail

DefaultButtonModelback to summary
public DefaultButtonModel()

Constructs a DefaultButtonModel.

Method Detail

addActionListenerback to summary
public void addActionListener(ActionListener l)

Implements javax.swing.ButtonModel.addActionListener.

Doc from javax.swing.ButtonModel.addActionListener.

Adds an ActionListener to the model.

Parameters
l:ActionListener

the listener to add

addChangeListenerback to summary
public void addChangeListener(ChangeListener l)

Implements javax.swing.ButtonModel.addChangeListener.

Doc from javax.swing.ButtonModel.addChangeListener.

Adds a ChangeListener to the model.

Parameters
l:ChangeListener

the listener to add

addItemListenerback to summary
public void addItemListener(ItemListener l)

Implements javax.swing.ButtonModel.addItemListener.

Doc from javax.swing.ButtonModel.addItemListener.

Adds an ItemListener to the model.

Parameters
l:ItemListener

the listener to add

fireActionPerformedback to summary
protected void fireActionPerformed(ActionEvent e)

Notifies all listeners that have registered interest for notification on this event type.

Parameters
e:ActionEvent

the ActionEvent to deliver to listeners

See Also
EventListenerList
fireItemStateChangedback to summary
protected void fireItemStateChanged(ItemEvent e)

Notifies all listeners that have registered interest for notification on this event type.

Parameters
e:ItemEvent

the ItemEvent to deliver to listeners

See Also
EventListenerList
fireStateChangedback to summary
protected void fireStateChanged()

Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.

See Also
EventListenerList
getActionCommandback to summary
public String getActionCommand()

Implements javax.swing.ButtonModel.getActionCommand.

Doc from javax.swing.ButtonModel.getActionCommand.

Returns the action command string for the button.

Returns:String

the String that identifies the generated event

getActionListenersback to summary
public ActionListener[] getActionListeners()

Returns an array of all the action listeners registered on this DefaultButtonModel.

Returns:ActionListener[]

all of this model's ActionListeners or an empty array if no action listeners are currently registered

Since
1.4
See Also
addActionListener, removeActionListener
getChangeListenersback to summary
public ChangeListener[] getChangeListeners()

Returns an array of all the change listeners registered on this DefaultButtonModel.

Returns:ChangeListener[]

all of this model's ChangeListeners or an empty array if no change listeners are currently registered

Since
1.4
See Also
addChangeListener, removeChangeListener
getGroupback to summary
public ButtonGroup getGroup()

Overrides default javax.swing.ButtonModel.getGroup.

Returns the group that the button belongs to. Normally used with radio buttons, which are mutually exclusive within their group.

Returns:ButtonGroup

the ButtonGroup that the button belongs to

Since
1.3
getItemListenersback to summary
public ItemListener[] getItemListeners()

Returns an array of all the item listeners registered on this DefaultButtonModel.

Returns:ItemListener[]

all of this model's ItemListeners or an empty array if no item listeners are currently registered

Since
1.4
See Also
addItemListener, removeItemListener
getListenersback to summary
public <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.
Parameters
<T>
the type of requested listeners
listenerType:Class<T>

the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener

Returns:T[]

an array of all objects registered as FooListeners on this model, or an empty array if no such listeners have been added

Exceptions
ClassCastException:
if listenerType doesn't specify a class or interface that implements java.util.EventListener
Since
1.3
See Also
getActionListeners, getChangeListeners, getItemListeners
getMnemonicback to summary
public int getMnemonic()

Implements javax.swing.ButtonModel.getMnemonic.

Doc from javax.swing.ButtonModel.getMnemonic.

Gets the keyboard mnemonic for the button.

Returns:int

an int specifying the accelerator key

getSelectedObjectsback to summary
public Object[] getSelectedObjects()

Implements java.awt.ItemSelectable.getSelectedObjects.

Overridden to return null.

Returns:Object[]

Doc from java.awt.ItemSelectable.getSelectedObjects.

the list of selected objects, or null

isArmedback to summary
public boolean isArmed()

Implements javax.swing.ButtonModel.isArmed.

Doc from javax.swing.ButtonModel.isArmed.

Indicates partial commitment towards triggering the button.

Returns:boolean

true if the button is armed, and ready to be triggered

isEnabledback to summary
public boolean isEnabled()

Implements javax.swing.ButtonModel.isEnabled.

Doc from javax.swing.ButtonModel.isEnabled.

Indicates if the button can be selected or triggered by an input device, such as a mouse pointer.

Returns:boolean

true if the button is enabled

isMenuItemback to summary
pack-priv boolean isMenuItem()
isPressedback to summary
public boolean isPressed()

Implements javax.swing.ButtonModel.isPressed.

Doc from javax.swing.ButtonModel.isPressed.

Indicates if the button is pressed.

Returns:boolean

true if the button is pressed

isRolloverback to summary
public boolean isRollover()

Implements javax.swing.ButtonModel.isRollover.

Doc from javax.swing.ButtonModel.isRollover.

Indicates that the mouse is over the button.

Returns:boolean

true if the mouse is over the button

isSelectedback to summary
public boolean isSelected()

Implements javax.swing.ButtonModel.isSelected.

Doc from javax.swing.ButtonModel.isSelected.

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

Returns:boolean

true if the button is selected

removeActionListenerback to summary
public void removeActionListener(ActionListener l)

Implements javax.swing.ButtonModel.removeActionListener.

Doc from javax.swing.ButtonModel.removeActionListener.

Removes an ActionListener from the model.

Parameters
l:ActionListener

the listener to remove

removeChangeListenerback to summary
public void removeChangeListener(ChangeListener l)

Implements javax.swing.ButtonModel.removeChangeListener.

Doc from javax.swing.ButtonModel.removeChangeListener.

Removes a ChangeListener from the model.

Parameters
l:ChangeListener

the listener to remove

removeItemListenerback to summary
public void removeItemListener(ItemListener l)

Implements javax.swing.ButtonModel.removeItemListener.

Doc from javax.swing.ButtonModel.removeItemListener.

Removes an ItemListener from the model.

Parameters
l:ItemListener

the listener to remove

setActionCommandback to summary
public void setActionCommand(String actionCommand)

Implements javax.swing.ButtonModel.setActionCommand.

Doc from javax.swing.ButtonModel.setActionCommand.

Sets the action command string that gets sent as part of the ActionEvent when the button is triggered.

Parameters
actionCommand:String

the String that identifies the generated event

setArmedback to summary
public void setArmed(boolean b)

Implements javax.swing.ButtonModel.setArmed.

Doc from javax.swing.ButtonModel.setArmed.

Marks the button as armed or unarmed.

Parameters
b:boolean

whether or not the button should be armed

setEnabledback to summary
public void setEnabled(boolean b)

Implements javax.swing.ButtonModel.setEnabled.

Doc from javax.swing.ButtonModel.setEnabled.

Enables or disables the button.

Parameters
b:boolean

whether or not the button should be enabled

setGroupback to summary
public void setGroup(ButtonGroup group)

Implements javax.swing.ButtonModel.setGroup.

Doc from javax.swing.ButtonModel.setGroup.

Identifies the group the button belongs to -- needed for radio buttons, which are mutually exclusive within their group.

Parameters
group:ButtonGroup

the ButtonGroup the button belongs to

setMenuItemback to summary
pack-priv void setMenuItem(boolean menuItem)
setMnemonicback to summary
public void setMnemonic(int key)

Implements javax.swing.ButtonModel.setMnemonic.

Doc from javax.swing.ButtonModel.setMnemonic.

Sets the keyboard mnemonic (shortcut key or accelerator key) for the button.

Parameters
key:int

an int specifying the accelerator key

setPressedback to summary
public void setPressed(boolean b)

Implements javax.swing.ButtonModel.setPressed.

Doc from javax.swing.ButtonModel.setPressed.

Sets the button to pressed or unpressed.

Parameters
b:boolean

whether or not the button should be pressed

Annotations
@SuppressWarnings:deprecation
setRolloverback to summary
public void setRollover(boolean b)

Implements javax.swing.ButtonModel.setRollover.

Doc from javax.swing.ButtonModel.setRollover.

Sets or clears the button's rollover state

Parameters
b:boolean

whether or not the button is in the rollover state

setSelectedback to summary
public void setSelected(boolean b)

Implements javax.swing.ButtonModel.setSelected.

Doc from javax.swing.ButtonModel.setSelected.

Selects or deselects the button.

Parameters
b:boolean

true selects the button, false deselects the button