Buttons can be configured, and to some degree controlled, by
Actions. Using an
Action with a button has many benefits beyond directly
configuring a button. Refer to
Swing Components Supporting Action for more
details, and you can find more information in How
to Use Actions, a section in The Java Tutorial.
For further information see How to Use Buttons, Check Boxes, and Radio Buttons, a section in The Java Tutorial.
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 java..
| Modifier and Type | Class and Description |
|---|---|
| protected abstract class | AbstractButton.
This class implements accessibility support for the
|
| private static class | |
| protected class | AbstractButton.
Extends |
| pack-priv class |
| Modifier and Type | Field and Description |
|---|---|
| private Action | |
| protected ActionListener | actionListener
The button model's |
| private PropertyChangeListener | |
| public static final String | BORDER_PAINTED_CHANGED_PROPERTY
Identifies a change to having the border drawn, or having it not drawn. |
| private boolean | |
| protected transient ChangeEvent | changeEvent
Only one |
| protected ChangeListener | changeListener
The button model's |
| public static final String | CONTENT_AREA_FILLED_CHANGED_PROPERTY
Identifies a change to having the button paint the content area. |
| private boolean | |
| private boolean | |
| pack-priv boolean | |
| private Icon | |
| private Insets | |
| public static final String | DISABLED_ICON_CHANGED_PROPERTY
Identifies a change to the icon used when the button has been disabled. |
| public static final String | DISABLED_SELECTED_ICON_CHANGED_PROPERTY
Identifies a change to the icon used when the button has been disabled and selected. |
| private Icon | |
| private Icon | |
| public static final String | FOCUS_PAINTED_CHANGED_PROPERTY
Identifies a change to having the border highlighted when focused, or not. |
| private AbstractButton. | handler
Combined listeners: ActionListener, ChangeListener, ItemListener. |
| private boolean | |
| public static final String | HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY
Identifies a change in the button's horizontal alignment. |
| public static final String | HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY
Identifies a change in the button's horizontal text position. |
| private int | |
| private int | |
| public static final String | ICON_CHANGED_PROPERTY
Identifies a change to the icon that represents the button. |
| private int | |
| private boolean | |
| protected ItemListener | itemListener
The button model's |
| private Insets | |
| public static final String | MARGIN_CHANGED_PROPERTY
Identifies a change in the button's margins. |
| private int | |
| public static final String | MNEMONIC_CHANGED_PROPERTY
Identifies a change to the button's mnemonic. |
| private int | |
| protected ButtonModel | model
The data model that determines the button's state. |
| public static final String | MODEL_CHANGED_PROPERTY
Identifies a change in the button model. |
| private long | |
| private boolean | |
| private boolean | |
| public static final String | PRESSED_ICON_CHANGED_PROPERTY
Identifies a change to the icon used when the button has been pressed. |
| private Icon | |
| public static final String | ROLLOVER_ENABLED_CHANGED_PROPERTY
Identifies a change from rollover enabled to disabled or back to enabled. |
| public static final String | ROLLOVER_ICON_CHANGED_PROPERTY
Identifies a change to the icon used when the cursor is over the button. |
| public static final String | ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY
Identifies a change to the icon used when the cursor is over the button and it has been selected. |
| private boolean | |
| private boolean | |
| private Icon | |
| private Icon | |
| public static final String | SELECTED_ICON_CHANGED_PROPERTY
Identifies a change to the icon used when the button has been selected. |
| private Icon | |
| private boolean | |
| private String | |
| public static final String | TEXT_CHANGED_PROPERTY
Identifies a change in the button's text. |
| public static final String | VERTICAL_ALIGNMENT_CHANGED_PROPERTY
Identifies a change in the button's vertical alignment. |
| public static final String | VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
Identifies a change in the button's vertical text position. |
| private int | |
| private int |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| protected void | actionPropertyChanged(Action
the action, String Action associated with this buttonthe name of the property that changed propertyName)Updates the button's state in response to property changes in the associated action. |
| public void | addActionListener(ActionListener
the l)ActionListener to be addedAdds an |
| public void | |
| protected void | addImpl(Component
the component to be added comp, Object an object expressing layout constraints
for this component constraints, int the position in the container's list at which to
insert the component, where index)-1
means append to the endOverrides java. Adds the specified component to this container at the specified
index, refer to
|
| public void | addItemListener(ItemListener
the l)ItemListener to be addedImplements java. Adds an |
| protected int | Returns: thekey argumentthe property value to check key, String the message to use in the
exception)IllegalArgumentException that is thrown for an invalid
valueVerify that the |
| protected int | Returns: thekey argumentthe property value to check key, String the message to use in the
exception)IllegalArgumentException that is thrown for an invalid
valueVerify that the |
| pack-priv void | clientPropertyChanged(Object key, Object oldValue, Object newValue)
Overrides javax.
|
| protected void | configurePropertiesFromAction(Action
the a)Action from which to get the properties,
or nullSets the properties on this button to match those in the specified
|
| protected ActionListener | |
| protected PropertyChangeListener | Returns: thePropertyChangeListenerthe button's action a)Creates and returns a |
| pack-priv PropertyChangeListener | |
| protected ChangeListener | Returns: the newChangeListenerSubclasses that want to handle |
| protected ItemListener | |
| public void | |
| public void | doClick(int
the time to "hold down" the button, in milliseconds pressTime)Programmatically perform a "click". |
| protected void | fireActionPerformed(ActionEvent
the event)ActionEvent objectNotifies all listeners that have registered interest for notification on this event type. |
| protected void | fireItemStateChanged(ItemEvent
the event)ItemEvent objectNotifies 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. |
| public Action | Returns: theAction for this ActionEvent
source, or nullReturns the currently set |
| public String | Returns: the action command for this buttonReturns the action command for this button. |
| public ActionListener[] | Returns: all of theActionListeners added or an empty
array if no listeners have been addedReturns an array of all the |
| public ChangeListener[] | Returns: all of theChangeListeners added or an empty
array if no listeners have been addedReturns an array of all the |
| public Icon | Returns: thedisabledIcon propertyReturns the icon used by the button when it's disabled. |
| public Icon | Returns: thedisabledSelectedIcon propertyReturns the icon used by the button when it's disabled and selected. |
| public int | Returns: index representing mnemonic characterReturns the character, as an index, that the look and feel should provide decoration for as representing the mnemonic character. |
| private AbstractButton. | |
| public boolean | Returns: true if the button's text
property should not reflect that of the
Action; the default is falseReturns the value of the |
| public int | Returns: thehorizontalAlignment property,
one of the following values:
Returns the horizontal alignment of the icon and text. |
| public int | Returns: thehorizontalTextPosition property,
one of the following values:
Returns the horizontal position of the text relative to the icon. |
| public Icon | |
| public int | Returns: an int equal to the number of pixels between the text and the icon.Returns the amount of space between the text and the icon displayed in this button. |
| public ItemListener[] | Returns: all of theItemListeners added or an empty
array if no listeners have been addedReturns an array of all the |
| public String | Returns: aString containing the label
Deprecated
- Replaced by
getText
Returns the label text. |
| public Insets | Returns: anInsets object specifying the margin
between the botton's border and the labelReturns the margin between the button's border and the label. |
| public int | Returns: the keyboard mnemonic from the modelReturns the keyboard mnemonic from the current model. |
| public ButtonModel | |
| public long | Returns: the amount of time required between mouse press events to generate corresponding action eventsGets the amount of time (in milliseconds) required between mouse press events for the button to generate the corresponding action events. |
| public Icon | |
| public Icon | |
| public Icon | Returns: therolloverSelectedIcon propertyReturns the rollover selection icon for the button. |
| public Icon | |
| public Object[] | Returns: an array containing 1 Object: the text of the button, if the item is selected; otherwisenullImplements java. Returns an array (length 1) containing the label or
|
| public String | |
| public ButtonUI | Returns: the ButtonUI objectOverrides javax. Returns the L&F object that renders this component. |
| public int | Returns: theverticalAlignment property, one of the
following values:
Returns the vertical alignment of the text and icon. |
| public int | Returns: theverticalTextPosition property,
one of the following values:
Returns the vertical position of the text relative to the icon. |
| public boolean | imageUpdate(Image
the img, int Image to be comparedflags used to repaint the button when the image
is updated and which determine how much is to be painted infoflags, int the x coordinate x, int the y coordinate y, int the width w, int the height h)Overrides java. Implements java. If the button icon for the current button state is either |
| protected void | |
| public boolean | |
| public boolean | |
| public boolean | |
| private boolean | |
| public boolean | Returns: the value of therolloverEnabled propertyGets the |
| public boolean | Returns: true if the toggle button is selected, otherwise falseReturns the state of the button. |
| pack-priv void | |
| protected void | paintBorder(Graphics
the g)Graphics context in which to paintOverrides javax. Paint the button's border if |
| protected String | Returns: a string representation of thisAbstractButtonOverrides javax. Returns a string representation of this |
| public void | removeActionListener(ActionListener
the listener to be removed l)Removes an |
| public void | removeChangeListener(ChangeListener
the listener to be removed l)Removes a ChangeListener from the button. |
| public void | removeItemListener(ItemListener
the l)ItemListener to be removedImplements java. Removes an |
| public void | removeNotify()
Overrides javax. Notifies this component that it no longer has a parent component. |
| public void | |
| public void | setActionCommand(String
the action command for this button actionCommand)Sets the action command for this button. |
| private void | |
| public void | setBorderPainted(boolean
if true and border property is not b)null,
the border is paintedSets the |
| public void | setContentAreaFilled(boolean
if true, the content should be filled; if false
the content area is not filled b)Sets the |
| public void | setDisabledIcon(Icon
the icon used as the disabled image disabledIcon)Sets the disabled icon for the button. |
| public void | setDisabledSelectedIcon(Icon
the icon used as the disabled
selection image disabledSelectedIcon)Sets the disabled selection icon for the button. |
| public void | setDisplayedMnemonicIndex(int
Index into the String to underline index)Provides a hint to the look and feel as to which character in the text should be decorated to represent the mnemonic. |
| private void | |
| public void | setEnabled(boolean
true to enable the button, otherwise false b)Overrides javax. Enables (or disables) the button. |
| public void | setFocusPainted(boolean
if b)true, the focus state should be paintedSets the |
| public void | setHideActionText(boolean
true if the button's
text property should not reflect
that of the Action; the default is
falseSets the |
| public void | setHorizontalAlignment(int
the alignment value, one of the following values:
alignment)
Sets the horizontal alignment of the icon and text. |
| public void | setHorizontalTextPosition(int
one of the following values:
textPosition)
Sets the horizontal position of the text relative to the icon. |
| public void | |
| pack-priv void | |
| public void | setIconTextGap(int
the space between icon and text if these properties are set. iconTextGap)If both the icon and text properties are set, this property defines the space between them. |
| public void | |
| public void | setLayout(LayoutManager
the specified layout manager mgr)Overrides java. Sets the layout manager for this container, refer to
|
| public void | |
| public void | setMnemonic(int
the key code which represents the mnemonic mnemonic)Sets the keyboard mnemonic on the current model. |
| public void | setMnemonic(char
a char specifying the mnemonic value mnemonic)This method is now obsolete, please use |
| private void | |
| public void | |
| public void | setMultiClickThreshhold(long
the amount of time required between mouse
press events to generate corresponding action events threshold)Sets the amount of time (in milliseconds) required between mouse press events for the button to generate the corresponding action events. |
| public void | setPressedIcon(Icon
the icon used as the "pressed" image pressedIcon)Sets the pressed icon for the button. |
| public void | setRolloverEnabled(boolean
if b)true, rollover effects should be paintedSets the |
| public void | setRolloverIcon(Icon
the icon used as the "rollover" image rolloverIcon)Sets the rollover icon for the button. |
| public void | setRolloverSelectedIcon(Icon
the icon used as the
"selected rollover" image rolloverSelectedIcon)Sets the rollover selected icon for the button. |
| public void | |
| private void | |
| public void | setSelectedIcon(Icon
the icon used as the "selected" image selectedIcon)Sets the selected icon for the button. |
| public void | |
| private void | |
| public void | |
| pack-priv void | |
| public void | setVerticalAlignment(int
one of the following values:
alignment)
Sets the vertical alignment of the icon and text. |
| public void | setVerticalTextPosition(int
one of the following values:
textPosition)
Sets the vertical position of the text relative to the icon. |
| pack-priv boolean | shouldUpdateSelectedStateFromAction()
Button subclasses that support mirroring the selected state from the action should override this to return true. |
| pack-priv void | |
| private void | |
| private void | |
| public void | updateUI()
Overrides javax. Resets the UI property to a value from the current look and feel. |