- 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 JavaBeansTM has been added to the
java.beanspackage. Please seeXMLEncoder.
-
-
Field Summary
Fields Modifier and Type Field and 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 Summary
Constructors Constructor and Description DefaultButtonModel()Constructs aDefaultButtonModel.
-
Method Summary
Methods Modifier and Type Method and Description voidaddActionListener(ActionListener l)Adds anActionListenerto the model.voidaddChangeListener(ChangeListener l)Adds aChangeListenerto the model.voidaddItemListener(ItemListener l)Adds anItemListenerto the model.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.StringgetActionCommand()Returns the action command string for the button.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.intgetMnemonic()Gets the keyboard mnemonic for the button.Object[]getSelectedObjects()Overridden to returnnull.booleanisArmed()Indicates partial commitment towards triggering the button.booleanisEnabled()Indicates if the button can be selected or triggered by an input device, such as a mouse pointer.booleanisPressed()Indicates if the button is pressed.booleanisRollover()Indicates that the mouse is over the button.booleanisSelected()Indicates if the button has been selected.voidremoveActionListener(ActionListener l)Removes anActionListenerfrom the model.voidremoveChangeListener(ChangeListener l)Removes aChangeListenerfrom the model.voidremoveItemListener(ItemListener l)Removes 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 Detail
-
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 oneChangeEventis 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
-
-
Method Detail
-
setActionCommand
public void setActionCommand(String actionCommand)
Sets the action command string that gets sent as part of theActionEventwhen the button is triggered.- Specified by:
setActionCommandin interfaceButtonModel- Parameters:
actionCommand- theStringthat identifies the generated event- See Also:
ButtonModel.getActionCommand(),ActionEvent.getActionCommand()
-
getActionCommand
public String getActionCommand()
Returns the action command string for the button.- Specified by:
getActionCommandin interfaceButtonModel- Returns:
- the
Stringthat identifies the generated event - See Also:
ButtonModel.setActionCommand(java.lang.String)
-
isArmed
public boolean isArmed()
Indicates partial commitment towards triggering the button.- Specified by:
isArmedin interfaceButtonModel- Returns:
trueif the button is armed, and ready to be triggered- See Also:
ButtonModel.setArmed(boolean)
-
isSelected
public 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 interfaceButtonModel- Returns:
trueif the button is selected
-
isEnabled
public boolean isEnabled()
Indicates if the button can be selected or triggered by an input device, such as a mouse pointer.- Specified by:
isEnabledin interfaceButtonModel- Returns:
trueif the button is enabled
-
isPressed
public boolean isPressed()
Indicates if the button is pressed.- Specified by:
isPressedin interfaceButtonModel- Returns:
trueif the button is pressed
-
isRollover
public boolean isRollover()
Indicates that the mouse is over the button.- Specified by:
isRolloverin interfaceButtonModel- Returns:
trueif the mouse is over the button
-
setArmed
public void setArmed(boolean b)
Marks the button as armed or unarmed.- Specified by:
setArmedin interfaceButtonModel- Parameters:
b- whether or not the button should be armed
-
setEnabled
public void setEnabled(boolean b)
Enables or disables the button.- Specified by:
setEnabledin interfaceButtonModel- Parameters:
b- whether or not the button should be enabled- See Also:
ButtonModel.isEnabled()
-
setSelected
public void setSelected(boolean b)
Selects or deselects the button.- Specified by:
setSelectedin interfaceButtonModel- Parameters:
b-trueselects the button,falsedeselects the button
-
setPressed
public void setPressed(boolean b)
Sets the button to pressed or unpressed.- Specified by:
setPressedin interfaceButtonModel- Parameters:
b- whether or not the button should be pressed- See Also:
ButtonModel.isPressed()
-
setRollover
public void setRollover(boolean b)
Sets or clears the button's rollover state- Specified by:
setRolloverin interfaceButtonModel- Parameters:
b- whether or not the button is in the rollover state- See Also:
ButtonModel.isRollover()
-
setMnemonic
public void setMnemonic(int key)
Sets the keyboard mnemonic (shortcut key or accelerator key) for the button.- Specified by:
setMnemonicin interfaceButtonModel- Parameters:
key- an int specifying the accelerator key
-
getMnemonic
public int getMnemonic()
Gets the keyboard mnemonic for the button.- Specified by:
getMnemonicin interfaceButtonModel- Returns:
- an int specifying the accelerator key
- See Also:
ButtonModel.setMnemonic(int)
-
addChangeListener
public void addChangeListener(ChangeListener l)
Adds aChangeListenerto the model.- Specified by:
addChangeListenerin interfaceButtonModel- Parameters:
l- the listener to add
-
removeChangeListener
public void removeChangeListener(ChangeListener l)
Removes aChangeListenerfrom the model.- Specified by:
removeChangeListenerin interfaceButtonModel- Parameters:
l- the listener to remove
-
getChangeListeners
public 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:
addChangeListener(javax.swing.event.ChangeListener),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
-
addActionListener
public void addActionListener(ActionListener l)
Adds anActionListenerto the model.- Specified by:
addActionListenerin interfaceButtonModel- Parameters:
l- the listener to add
-
removeActionListener
public void removeActionListener(ActionListener l)
Removes anActionListenerfrom the model.- Specified by:
removeActionListenerin interfaceButtonModel- Parameters:
l- the listener to remove
-
getActionListeners
public 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:
addActionListener(java.awt.event.ActionListener),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- theActionEventto deliver to listeners- See Also:
EventListenerList
-
addItemListener
public void addItemListener(ItemListener l)
Adds anItemListenerto the model.- Specified by:
addItemListenerin interfaceItemSelectable- Specified by:
addItemListenerin interfaceButtonModel- Parameters:
l- the listener to add- See Also:
ItemEvent
-
removeItemListener
public void removeItemListener(ItemListener l)
Removes anItemListenerfrom the model.- Specified by:
removeItemListenerin interfaceItemSelectable- Specified by:
removeItemListenerin interfaceButtonModel- Parameters:
l- the listener to remove- See Also:
ItemEvent
-
getItemListeners
public 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:
addItemListener(java.awt.event.ItemListener),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- theItemEventto 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 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.- 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:
getActionListeners(),getChangeListeners(),getItemListeners()
-
getSelectedObjects
public Object[] getSelectedObjects()
Overridden to returnnull.- Specified by:
getSelectedObjectsin interfaceItemSelectable
-
setGroup
public void setGroup(ButtonGroup group)
Identifies the group the button belongs to -- needed for radio buttons, which are mutually exclusive within their group.- Specified by:
setGroupin interfaceButtonModel- Parameters:
group- theButtonGroupthe button belongs to
-
getGroup
public ButtonGroup getGroup()
Returns the group that the button belongs to. Normally used with radio buttons, which are mutually exclusive within their group.- Returns:
- the
ButtonGroupthat the button belongs to - Since:
- 1.3
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-javax/swing/DefaultButtonModel.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor dieser Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.