Class DefaultButtonModel
- 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 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
- See Also:
- Serialized Form
Fields
Modifier and Type | Field | Description |
---|---|---|
protected String | actionCommand | The action command string fired by the button. |
static int | ARMED | Identifies the "armed" bit in the bitmask, which indicates partial commitment towards choosing/triggering the button. |
protected ChangeEvent | changeEvent | Only one |
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). |
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. |
static int | PRESSED | Identifies the "pressed" bit in the bitmask, which indicates that the button is pressed. |
static int | ROLLOVER | Identifies the "rollover" bit in the bitmask, which indicates that the mouse is over the button. |
static 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. |
Constructors
Constructor | Description |
---|---|
DefaultButtonModel() | Constructs a |
Methods
Modifier and Type | Method | Description |
---|---|---|
protected void | fireActionPerformed(ActionEvent e) | Notifies all listeners that have registered interest for notification on this event type. |
protected void | fireItemStateChanged(ItemEvent 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. |
ActionListener[] | getActionListeners() | Returns an array of all the action listeners registered on this |
ChangeListener[] | getChangeListeners() | Returns an array of all the change listeners registered on this |
ButtonGroup | getGroup() | Returns the group that the button belongs to. |
ItemListener[] | getItemListeners() | Returns an array of all the item listeners registered on this |
<T extends EventListener> | getListeners(Class<T> listenerType) | Returns an array of all the objects currently registered as |
Object[] | getSelectedObjects() | Overridden to return |
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods declared in interface javax.swing.ButtonModel
addActionListener, addChangeListener, addItemListener, getActionCommand, getMnemonic, isArmed, isEnabled, isPressed, isRollover, isSelected, removeActionListener, removeChangeListener, removeItemListener, setActionCommand, setArmed, setEnabled, setGroup, setMnemonic, setPressed, setRollover, setSelected
Fields
stateMask
protected int stateMask
The bitmask used to store the state of the button.
actionCommand
protected String actionCommand
The action command string fired by the button.
group
protected ButtonGroup group
The button group that the button belongs to.
mnemonic
protected int mnemonic
The button's mnemonic.
changeEvent
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".
listenerList
protected EventListenerList listenerList
Stores the listeners on this model.
ARMED
public 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
SELECTED
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.
- See Also:
- Constant Field Values
PRESSED
public static final int PRESSED
Identifies the "pressed" bit in the bitmask, which indicates that the button is pressed.
- See Also:
- Constant Field Values
ENABLED
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).
- See Also:
- Constant Field Values
ROLLOVER
public 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
Constructors
DefaultButtonModel
public DefaultButtonModel()
Constructs a DefaultButtonModel
.
Methods
getChangeListeners
public ChangeListener[] getChangeListeners()
Returns an array of all the change listeners registered on this DefaultButtonModel
.
- Returns:
- all of this model's
ChangeListener
s 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)
fireStateChanged
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
getActionListeners
public ActionListener[] getActionListeners()
Returns an array of all the action listeners registered on this DefaultButtonModel
.
- Returns:
- all of this model's
ActionListener
s 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)
fireActionPerformed
protected void fireActionPerformed(ActionEvent e)
Notifies all listeners that have registered interest for notification on this event type.
- Parameters:
-
e
- theActionEvent
to deliver to listeners - See Also:
EventListenerList
getItemListeners
public ItemListener[] getItemListeners()
Returns an array of all the item listeners registered on this DefaultButtonModel
.
- Returns:
- all of this model's
ItemListener
s 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)
fireItemStateChanged
protected void fireItemStateChanged(ItemEvent e)
Notifies all listeners that have registered interest for notification on this event type.
- Parameters:
-
e
- theItemEvent
to deliver to listeners - See Also:
EventListenerList
getListeners
public <T extends EventListener> T[] getListeners(Class<T> listenerType)
Returns an array of all the objects currently registered as FooListener
s upon this model. FooListener
s 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.
- Type Parameters:
-
T
- the type of requested listeners - Parameters:
-
listenerType
- the type of listeners requested; this parameter should specify an interface that descends fromjava.util.EventListener
- Returns:
- an array of all objects registered as
FooListener
s on this model, or an empty array if no such listeners have been added - Throws:
-
ClassCastException
- iflistenerType
doesn't specify a class or interface that implementsjava.util.EventListener
- Since:
- 1.3
- See Also:
-
getActionListeners()
,getChangeListeners()
,getItemListeners()
getSelectedObjects
public Object[] getSelectedObjects()
Overridden to return null
.
- Specified by:
-
getSelectedObjects
in interfaceItemSelectable
- Returns:
- the list of selected objects, or
null
getGroup
public ButtonGroup getGroup()
Returns the group that the button belongs to. Normally used with radio buttons, which are mutually exclusive within their group.
- Specified by:
-
getGroup
in interfaceButtonModel
- Returns:
- the
ButtonGroup
that the button belongs to - Since:
- 1.3
© 1993, 2020, 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.
https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/swing/DefaultButtonModel.html