Class DefaultButtonModel
- All Implemented Interfaces:
-
ItemSelectable,Serializable,ButtonModel
- Direct Known Subclasses:
JToggleButton.ToggleButtonModel
public class DefaultButtonModel extends Object implements ButtonModel, Serializable
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 Summary
| Modifier and Type | Field | Description |
|---|---|---|
protected String |
actionCommand |
The action command string fired by the button. |
static final int |
ARMED |
Identifies the "armed" bit in the bitmask, which indicates partial commitment towards choosing/triggering the button. |
protected ChangeEvent |
changeEvent |
Only one ChangeEvent is needed per button model instance since the event's only state is the source property. |
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. |
static final int |
PRESSED |
Identifies the "pressed" bit in the bitmask, which indicates that the button is pressed. |
static final int |
ROLLOVER |
Identifies the "rollover" bit in the bitmask, which indicates that the mouse is over the button. |
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
| Constructor | Description |
|---|---|
DefaultButtonModel() |
Constructs a DefaultButtonModel. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
void |
addActionListener |
Adds an ActionListener to the model. |
void |
addChangeListener |
Adds a ChangeListener to the model. |
void |
addItemListener |
Adds an ItemListener to the model. |
protected void |
fireActionPerformed |
Notifies all listeners that have registered interest for notification on this event type. |
protected void |
fireItemStateChanged |
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. |
String |
getActionCommand() |
Returns the action command string for the button. |
ActionListener[] |
getActionListeners() |
Returns an array of all the action listeners registered on this DefaultButtonModel. |
ChangeListener[] |
getChangeListeners() |
Returns an array of all the change listeners registered on this DefaultButtonModel. |
ButtonGroup |
getGroup() |
Returns the group that the button belongs to. |
ItemListener[] |
getItemListeners() |
Returns an array of all the item listeners registered on this DefaultButtonModel. |
<T extends EventListener> |
getListeners |
Returns an array of all the objects currently registered as FooListeners upon this model. |
int |
getMnemonic() |
Gets the keyboard mnemonic for the button. |
Object[] |
getSelectedObjects() |
Overridden to return null. |
boolean |
isArmed() |
Indicates partial commitment towards triggering the button. |
boolean |
isEnabled() |
Indicates if the button can be selected or triggered by an input device, such as a mouse pointer. |
boolean |
isPressed() |
Indicates if the button is pressed. |
boolean |
isRollover() |
Indicates that the mouse is over the button. |
boolean |
isSelected() |
Indicates if the button has been selected. |
void |
removeActionListener |
Removes an ActionListener from the model. |
void |
removeChangeListener |
Removes a ChangeListener from the model. |
void |
removeItemListener |
Removes an ItemListener from the model. |
void |
setActionCommand |
Sets the action command string that gets sent as part of the ActionEvent when the button is triggered. |
void |
setArmed |
Marks the button as armed or unarmed. |
void |
setEnabled |
Enables or disables the button. |
void |
setGroup |
Identifies the group the button belongs to -- needed for radio buttons, which are mutually exclusive within their group. |
void |
setMnemonic |
Sets the keyboard mnemonic (shortcut key or accelerator key) for the button. |
void |
setPressed |
Sets the button to pressed or unpressed. |
void |
setRollover |
Sets or clears the button's rollover state |
void |
setSelected |
Selects or deselects the button. |
Field Details
stateMask
protected int stateMask
actionCommand
protected String actionCommand
group
protected ButtonGroup group
mnemonic
protected int mnemonic
changeEvent
protected transient ChangeEvent changeEvent
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
ARMED
public static final int ARMED
- See Also:
SELECTED
public static final int SELECTED
- See Also:
PRESSED
public static final int PRESSED
- See Also:
ENABLED
public static final int ENABLED
- See Also:
ROLLOVER
public static final int ROLLOVER
- See Also:
Constructor Details
DefaultButtonModel
public DefaultButtonModel()
DefaultButtonModel.Method Details
setActionCommand
public void setActionCommand(String actionCommand)
ActionEvent when the button is triggered.- Specified by:
-
setActionCommandin interfaceButtonModel - Parameters:
-
actionCommand- theStringthat identifies the generated event - See Also:
getActionCommand
public String getActionCommand()
- Specified by:
-
getActionCommandin interfaceButtonModel - Returns:
- the
Stringthat identifies the generated event - See Also:
isArmed
public boolean isArmed()
- Specified by:
-
isArmedin interfaceButtonModel - Returns:
-
trueif the button is armed, and ready to be triggered - See Also:
isSelected
public boolean isSelected()
- Specified by:
-
isSelectedin interfaceButtonModel - Returns:
-
trueif the button is selected
isEnabled
public boolean isEnabled()
- Specified by:
-
isEnabledin interfaceButtonModel - Returns:
-
trueif the button is enabled
isPressed
public boolean isPressed()
- Specified by:
-
isPressedin interfaceButtonModel - Returns:
-
trueif the button is pressed
isRollover
public boolean isRollover()
- Specified by:
-
isRolloverin interfaceButtonModel - Returns:
-
trueif the mouse is over the button
setArmed
public void setArmed(boolean b)
- Specified by:
-
setArmedin interfaceButtonModel - Parameters:
-
b- whether or not the button should be armed
setEnabled
public void setEnabled(boolean b)
- Specified by:
-
setEnabledin interfaceButtonModel - Parameters:
-
b- whether or not the button should be enabled - See Also:
setSelected
public void setSelected(boolean b)
- Specified by:
-
setSelectedin interfaceButtonModel - Parameters:
-
b-trueselects the button,falsedeselects the button
setPressed
public void setPressed(boolean b)
- Specified by:
-
setPressedin interfaceButtonModel - Parameters:
-
b- whether or not the button should be pressed - See Also:
setRollover
public void setRollover(boolean b)
- Specified by:
-
setRolloverin interfaceButtonModel - Parameters:
-
b- whether or not the button is in the rollover state - See Also:
setMnemonic
public void setMnemonic(int key)
- Specified by:
-
setMnemonicin interfaceButtonModel - Parameters:
-
key- an int specifying the accelerator key
getMnemonic
public int getMnemonic()
- Specified by:
-
getMnemonicin interfaceButtonModel - Returns:
- an int specifying the accelerator key
- See Also:
addChangeListener
public void addChangeListener(ChangeListener l)
ChangeListener to the model.- Specified by:
-
addChangeListenerin interfaceButtonModel - Parameters:
-
l- the listener to add
removeChangeListener
public void removeChangeListener(ChangeListener l)
ChangeListener from the model.- Specified by:
-
removeChangeListenerin interfaceButtonModel - Parameters:
-
l- the listener to remove
getChangeListeners
public ChangeListener[] getChangeListeners()
DefaultButtonModel.- Returns:
- all of this model's
ChangeListeners or an empty array if no change listeners are currently registered - Since:
- 1.4
- See Also:
fireStateChanged
protected void fireStateChanged()
- See Also:
addActionListener
public void addActionListener(ActionListener l)
ActionListener to the model.- Specified by:
-
addActionListenerin interfaceButtonModel - Parameters:
-
l- the listener to add
removeActionListener
public void removeActionListener(ActionListener l)
ActionListener from the model.- Specified by:
-
removeActionListenerin interfaceButtonModel - Parameters:
-
l- the listener to remove
getActionListeners
public ActionListener[] getActionListeners()
DefaultButtonModel.- Returns:
- all of this model's
ActionListeners or an empty array if no action listeners are currently registered - Since:
- 1.4
- See Also:
fireActionPerformed
protected void fireActionPerformed(ActionEvent e)
- Parameters:
-
e- theActionEventto deliver to listeners - See Also:
addItemListener
public void addItemListener(ItemListener l)
ItemListener to the model.- Specified by:
-
addItemListenerin interfaceButtonModel - Specified by:
-
addItemListenerin interfaceItemSelectable - Parameters:
-
l- the listener to add - See Also:
removeItemListener
public void removeItemListener(ItemListener l)
ItemListener from the model.- Specified by:
-
removeItemListenerin interfaceButtonModel - Specified by:
-
removeItemListenerin interfaceItemSelectable - Parameters:
-
l- the listener to remove - See Also:
getItemListeners
public ItemListener[] getItemListeners()
DefaultButtonModel.- Returns:
- all of this model's
ItemListeners or an empty array if no item listeners are currently registered - Since:
- 1.4
- See Also:
fireItemStateChanged
protected void fireItemStateChanged(ItemEvent e)
- Parameters:
-
e- theItemEventto deliver to listeners - See Also:
getListeners
public <T extends EventListener> T[] getListeners(Class<T> listenerType)
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.
- 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
FooListeners on this model, or an empty array if no such listeners have been added - Throws:
-
ClassCastException- iflistenerTypedoesn't specify a class or interface that implementsjava.util.EventListener - Since:
- 1.3
- See Also:
getSelectedObjects
public Object[] getSelectedObjects()
null.- Specified by:
-
getSelectedObjectsin interfaceItemSelectable - Returns:
- the list of selected objects, or
null
setGroup
public void setGroup(ButtonGroup group)
- Specified by:
-
setGroupin interfaceButtonModel - Parameters:
-
group- theButtonGroupthe button belongs to
getGroup
public ButtonGroup getGroup()
- Specified by:
-
getGroupin interfaceButtonModel - Returns:
- the
ButtonGroupthat the button belongs to - Since:
- 1.3
© 1993, 2021, 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/17/docs/api/java.desktop/javax/swing/DefaultButtonModel.html