Package Summary  Overview Summary

class:DefaultButtonModel [CHANGED]

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™JavaBeans has been added to the java.beans package. Please see XMLEncoder.

Since:
1.2
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
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

field:stateMask [NONE]

  • stateMask

    protected int stateMask
    The bitmask used to store the state of the button.
  • field:actionCommand [NONE]

    actionCommand

    protected String actionCommand
    The action command string fired by the button.

    field:group [NONE]

    group

    protected ButtonGroup group
    The button group that the button belongs to.

    field:mnemonic [NONE]

    mnemonic

    protected int mnemonic
    The button's mnemonic.

    field:changeEvent [NONE]

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

    field:listenerList [NONE]

    listenerList

    protected EventListenerList listenerList
    Stores the listeners on this model.

    field:ARMED [NONE]

    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

    field:SELECTED [NONE]

    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

    field:PRESSED [NONE]

    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

    field:ENABLED [NONE]

    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

    field:ROLLOVER [NONE]

    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

    constructor:DefaultButtonModel() [NONE]

    method:setActionCommand(java.lang.String) [NONE]

  • setActionCommand

    public void setActionCommand?(String actionCommand)
    Sets the action command string that gets sent as part of the ActionEvent when the button is triggered.
    Specified by:
    setActionCommand in interface ButtonModel
    Parameters:
    actionCommand - the String that identifies the generated event
    See Also:
    ButtonModel.getActionCommand(), ActionEvent.getActionCommand()
  • method:getActionCommand() [NONE]

    getActionCommand

    public String getActionCommand()
    Returns the action command string for the button.
    Specified by:
    getActionCommand in interface ButtonModel
    Returns:
    the String that identifies the generated event
    See Also:
    ButtonModel.setActionCommand(java.lang.String)

    method:isArmed() [NONE]

    isArmed

    public boolean isArmed()
    Indicates partial commitment towards triggering the button.
    Specified by:
    isArmed in interface ButtonModel
    Returns:
    true if the button is armed, and ready to be triggered
    See Also:
    ButtonModel.setArmed(boolean)

    method:isSelected() [NONE]

    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:
    isSelected in interface ButtonModel
    Returns:
    true if the button is selected

    method:isEnabled() [NONE]

    isEnabled

    public boolean isEnabled()
    Indicates if the button can be selected or triggered by an input device, such as a mouse pointer.
    Specified by:
    isEnabled in interface ButtonModel
    Returns:
    true if the button is enabled

    method:isPressed() [NONE]

    isPressed

    public boolean isPressed()
    Indicates if the button is pressed.
    Specified by:
    isPressed in interface ButtonModel
    Returns:
    true if the button is pressed

    method:isRollover() [NONE]

    isRollover

    public boolean isRollover()
    Indicates that the mouse is over the button.
    Specified by:
    isRollover in interface ButtonModel
    Returns:
    true if the mouse is over the button

    method:setArmed(boolean) [NONE]

    setArmed

    public void setArmed?(boolean b)
    Marks the button as armed or unarmed.
    Specified by:
    setArmed in interface ButtonModel
    Parameters:
    b - whether or not the button should be armed

    method:setEnabled(boolean) [NONE]

    setEnabled

    public void setEnabled?(boolean b)
    Enables or disables the button.
    Specified by:
    setEnabled in interface ButtonModel
    Parameters:
    b - whether or not the button should be enabled
    See Also:
    ButtonModel.isEnabled()

    method:setSelected(boolean) [NONE]

    setSelected

    public void setSelected?(boolean b)
    Selects or deselects the button.
    Specified by:
    setSelected in interface ButtonModel
    Parameters:
    b - true selects the button, false deselects the button

    method:setPressed(boolean) [NONE]

    setPressed

    public void setPressed?(boolean b)
    Sets the button to pressed or unpressed.
    Specified by:
    setPressed in interface ButtonModel
    Parameters:
    b - whether or not the button should be pressed
    See Also:
    ButtonModel.isPressed()

    method:setRollover(boolean) [NONE]

    setRollover

    public void setRollover?(boolean b)
    Sets or clears the button's rollover state
    Specified by:
    setRollover in interface ButtonModel
    Parameters:
    b - whether or not the button is in the rollover state
    See Also:
    ButtonModel.isRollover()

    method:setMnemonic(int) [NONE]

    setMnemonic

    public void setMnemonic?(int key)
    Sets the keyboard mnemonic (shortcut key or accelerator key) for the button.
    Specified by:
    setMnemonic in interface ButtonModel
    Parameters:
    key - an int specifying the accelerator key

    method:getMnemonic() [NONE]

    getMnemonic

    public int getMnemonic()
    Gets the keyboard mnemonic for the button.
    Specified by:
    getMnemonic in interface ButtonModel
    Returns:
    an int specifying the accelerator key
    See Also:
    ButtonModel.setMnemonic(int)

    method:addChangeListener(javax.swing.event.ChangeListener) [NONE]

    addChangeListener

    public void addChangeListener?(ChangeListener l)
    Adds a ChangeListener to the model.
    Specified by:
    addChangeListener in interface ButtonModel
    Parameters:
    l - the listener to add

    method:removeChangeListener(javax.swing.event.ChangeListener) [NONE]

    removeChangeListener

    public void removeChangeListener?(ChangeListener l)
    Removes a ChangeListener from the model.
    Specified by:
    removeChangeListener in interface ButtonModel
    Parameters:
    l - the listener to remove

    method:getChangeListeners() [NONE]

    getChangeListeners

    public ChangeListener[] getChangeListeners()
    Returns an array of all the change listeners registered on this DefaultButtonModel.
    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)

    method:fireStateChanged() [NONE]

    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

    method:addActionListener(java.awt.event.ActionListener) [NONE]

    addActionListener

    public void addActionListener?(ActionListener l)
    Adds an ActionListener to the model.
    Specified by:
    addActionListener in interface ButtonModel
    Parameters:
    l - the listener to add

    method:removeActionListener(java.awt.event.ActionListener) [NONE]

    removeActionListener

    public void removeActionListener?(ActionListener l)
    Removes an ActionListener from the model.
    Specified by:
    removeActionListener in interface ButtonModel
    Parameters:
    l - the listener to remove

    method:getActionListeners() [NONE]

    getActionListeners

    public ActionListener[] getActionListeners()
    Returns an array of all the action listeners registered on this DefaultButtonModel.
    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)

    method:fireActionPerformed(java.awt.event.ActionEvent) [NONE]

    fireActionPerformed

    protected void fireActionPerformed?(ActionEvent e)
    Notifies all listeners that have registered interest for notification on this event type.
    Parameters:
    e - the ActionEvent to deliver to listeners
    See Also:
    EventListenerList

    method:addItemListener(java.awt.event.ItemListener) [NONE]

    addItemListener

    public void addItemListener?(ItemListener l)
    Adds an ItemListener to the model.
    Specified by:
    addItemListener in interface ButtonModel
    Specified by:
    addItemListener in interface ItemSelectable
    Parameters:
    l - the listener to add
    See Also:
    ItemEvent

    method:removeItemListener(java.awt.event.ItemListener) [NONE]

    removeItemListener

    public void removeItemListener?(ItemListener l)
    Removes an ItemListener from the model.
    Specified by:
    removeItemListener in interface ButtonModel
    Specified by:
    removeItemListener in interface ItemSelectable
    Parameters:
    l - the listener to remove
    See Also:
    ItemEvent

    method:getItemListeners() [NONE]

    getItemListeners

    public ItemListener[] getItemListeners()
    Returns an array of all the item listeners registered on this DefaultButtonModel.
    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)

    method:fireItemStateChanged(java.awt.event.ItemEvent) [NONE]

    fireItemStateChanged

    protected void fireItemStateChanged?(ItemEvent e)
    Notifies all listeners that have registered interest for notification on this event type.
    Parameters:
    e - the ItemEvent to deliver to listeners
    See Also:
    EventListenerList

    method:getListeners(java.lang.Class) [NONE]

    getListeners

    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.

    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 listenerType doesn't specify a class or interface that implements java.util.EventListener
    Since:
    1.3
    See Also:
    getActionListeners(), getChangeListeners(), getItemListeners()

    method:getSelectedObjects() [NONE]

    getSelectedObjects

    public Object[] getSelectedObjects()
    Overridden to return null.
    Specified by:
    getSelectedObjects in interface ItemSelectable
    Returns:
    the list of selected objects, or null

    method:setGroup(javax.swing.ButtonGroup) [NONE]

    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:
    setGroup in interface ButtonModel
    Parameters:
    group - the ButtonGroup the button belongs to

    method:getGroup() [NONE]

    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 interface ButtonModel
    Returns:
    the ButtonGroup that the button belongs to
    Since:
    1.3

    © 2020 Oracle Corporation and/or its affiliates