Java Platform 1.2

javax.swing
Class DefaultButtonModel

java.lang.Object
  |
  +--javax.swing.DefaultButtonModel
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. A future release of Swing will provide support for long term persistence.

See Also:
Serialized Form

Field Summary
protected  String actionCommand
           
static int ARMED
          Indicates partial commitment towards choosing 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 int ENABLED
          Indicates that the button can be selected by an input device (such as a mouse pointer).
protected  ButtonGroup group
           
protected  EventListenerList listenerList
           
protected  int mnemonic
           
static int PRESSED
          Indicates that the button has been "pressed" (typically, when the mouse is released).
static int ROLLOVER
          Indicates that the mouse is over the button.
static int SELECTED
          Indicates that the button has been selected.
protected  int stateMask
           
 
Constructor Summary
DefaultButtonModel()
          Constructs a JButtonModel
 
Method Summary
 void addActionListener(ActionListener l)
          Adds an ActionListener to the button.
 void addChangeListener(ChangeListener l)
          Adds a ChangeListener to the button.
 void addItemListener(ItemListener l)
          Adds an ItemListener to the button.
protected  void fireActionPerformed(ActionEvent e)
           
protected  void fireItemStateChanged(ItemEvent e)
           
protected  void fireStateChanged()
           
 String getActionCommand()
          Returns the action command for this button.
 int getMnemonic()
          Gets the keyboard mnemonic for this model
 Object[] getSelectedObjects()
          Overriden to return null
 boolean isArmed()
          Indicates partial commitment towards pressing the button.
 boolean isEnabled()
          Indicates if the button can be selected or pressed by an input device (such as a mouse pointer).
 boolean isPressed()
          Indicates if button has been pressed.
 boolean isRollover()
          Indicates that the mouse is over the button.
 boolean isSelected()
          Indicates if the button has been selected.
 void removeActionListener(ActionListener l)
          Removes an ActionListener from the button.
 void removeChangeListener(ChangeListener l)
          Removes a ChangeListener from the button.
 void removeItemListener(ItemListener l)
          Removes an ItemListener from the button.
 void setActionCommand(String actionCommand)
          Sets the actionCommand string that gets sent as part of the event when the button is pressed.
 void setArmed(boolean b)
          Marks the button as "armed".
 void setEnabled(boolean b)
          Enables or disables the button.
 void setGroup(ButtonGroup group)
          Identifies the group this button belongs to -- needed for radio buttons, which are mutually exclusive within their group.
 void setMnemonic(int key)
          Sets the keyboard mnemonic (shortcut key or accelerator key) for this button.
 void setPressed(boolean b)
          Sets the button to pressed or unpressed.
 void setRollover(boolean b)
          Sets or clears the button's rollover state
 void setSelected(boolean b)
          Selects or deselects the button.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stateMask

protected int stateMask

actionCommand

protected String actionCommand

group

protected ButtonGroup group

mnemonic

protected int 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

ARMED

public static final int ARMED
Indicates partial commitment towards choosing the button.

SELECTED

public static final int SELECTED
Indicates that the button has been selected. Only needed for certain types of buttons - such as RadioButton or Checkbox.

PRESSED

public static final int PRESSED
Indicates that the button has been "pressed" (typically, when the mouse is released).

ENABLED

public static final int ENABLED
Indicates that the button can be selected by an input device (such as a mouse pointer).

ROLLOVER

public static final int ROLLOVER
Indicates that the mouse is over the button.
Constructor Detail

DefaultButtonModel

public DefaultButtonModel()
Constructs a JButtonModel
Method Detail

setActionCommand

public void setActionCommand(String actionCommand)
Sets the actionCommand string that gets sent as part of the event when the button is pressed.
Specified by:
setActionCommand in interface ButtonModel
Parameters:
s - the String that identifies the generated event

getActionCommand

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

isArmed

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

isSelected

public boolean isSelected()
Indicates if the button has been selected. Only needed for certain types of buttons - such as RadioButton or Checkbox.
Specified by:
isSelected in interface ButtonModel
Returns:
true if the button is selected

isEnabled

public boolean isEnabled()
Indicates if the button can be selected or pressed by an input device (such as a mouse pointer). (Checkbox-buttons are selected, regular buttons are "pressed".)
Specified by:
isEnabled in interface ButtonModel
Returns:
true if the button is enabled, and therefore selectable (or pressable)

isPressed

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

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

setArmed

public void setArmed(boolean b)
Marks the button as "armed". If the mouse button is released while it is over this item, the button's action event fires. If the mouse button is released elsewhere, the event does not fire and the button is disarmed.
Specified by:
setArmed in interface ButtonModel
Parameters:
b - true to arm the button so it can be selected

setEnabled

public void setEnabled(boolean b)
Enables or disables the button.
Specified by:
setEnabled in interface ButtonModel
Parameters:
b - true to enable the button
See Also:
isEnabled()

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.

setPressed

public void setPressed(boolean b)
Sets the button to pressed or unpressed.
Specified by:
setPressed in interface ButtonModel
Parameters:
b - true to set the button to "pressed"
See Also:
isPressed()

setRollover

public void setRollover(boolean b)
Sets or clears the button's rollover state
Specified by:
setRollover in interface ButtonModel
Parameters:
b - true to turn on rollover
See Also:
isRollover()

setMnemonic

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

getMnemonic

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

addChangeListener

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

removeChangeListener

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

fireStateChanged

protected void fireStateChanged()

addActionListener

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

removeActionListener

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

fireActionPerformed

protected void fireActionPerformed(ActionEvent e)

addItemListener

public void addItemListener(ItemListener l)
Adds an ItemListener to the button.
Specified by:
addItemListener in interface ButtonModel
Parameters:
l - the listener to add

removeItemListener

public void removeItemListener(ItemListener l)
Removes an ItemListener from the button.
Specified by:
removeItemListener in interface ButtonModel
Parameters:
l - the listener to remove

fireItemStateChanged

protected void fireItemStateChanged(ItemEvent e)

getSelectedObjects

public Object[] getSelectedObjects()
Overriden to return null

setGroup

public void setGroup(ButtonGroup group)
Identifies the group this button belongs to -- needed for radio buttons, which are mutually exclusive within their group.
Specified by:
setGroup in interface ButtonModel
Parameters:
group - the ButtonGroup this button belongs to

Java Platform 1.2

Submit a bug or feature Version 1.2 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.