All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.AbstractButton

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----com.sun.java.swing.JComponent
                           |
                           +----com.sun.java.swing.AbstractButton

public abstract class AbstractButton
extends JComponent
implements ItemSelectable, SwingConstants
Defines the common behaviors for the JButton, JRadioButton, and JToggleButton classes.


Variable Index

 o actionListener
 o changeEvent
Only one ChangeEvent is needed per button instance since the event's only state is the source property.
 o changeListener
The button's model listeners.
 o itemListener
 o model

Constructor Index

 o AbstractButton()

Method Index

 o addActionListener(ActionListener)
adds an ActionListener to the button
 o addChangeListener(ChangeListener)
Adds a ChangeListener to the button.
 o addItemListener(ItemListener)
adds an ItemListener to the checkbox
 o checkHorizontalKey(int, String)
Ensures that the key is a valid.
 o checkVerticalKey(int, String)
Ensures that the key is a valid.
 o createActionListener()
 o createChangeListener()
Subclasses that want to handle ChangeEvents differently can override this to return another ChangeListener implementation.
 o createItemListener()
 o doClick()
Programatically perform a "click".
 o fireActionPerformed(ActionEvent)
 o fireItemStateChanged(ItemEvent)
 o fireStateChanged()
 o getAccessibleName()
Get the accessible name of this object.
 o getAccessibleStateSet()
Get the state set of this object.
 o getActionCommand()
Returns the action command for this button.
 o getDisabledIcon()
Returns the icon used by the button when it's disabled.
 o getDisabledSelectedIcon()
Returns the icon used by the button when it's disabled and selected.
 o getHorizontalAlignment()
Returns the horizontal alignment of the icon and text.
 o getHorizontalTextPosition()
Sets the horizontal position of the text relative to the icon.
 o getIcon()
Returns the default icon.
 o getKeyAccelerator()
Convenience to get the keyboard accelerator from the the current model
 o getLabel()
Deprecated.
 o getMargin()
Returns the margin between the button's border and the label.
 o getModel()
Get the model that this button represents.
 o getPressedIcon()
Returns the pressed icon for the button.
 o getRolloverIcon()
Returns the rollover icon for the button.
 o getRolloverSelectedIcon()
Returns the rollover seletion icon for the button.
 o getSelectedIcon()
Returns the selected icon for the button.
 o getSelectedObjects()
 o getText()
Returns the button's text.
 o getUI()
Returns the button's current UI.
 o getVerticalAlignment()
Returns the vertical alignment of the text and icon.
 o getVerticalTextPosition()
Returns the vertical position of the text relative to the icon Valid keys: CENTER (the default), TOP, BOTTOM
 o init(String, Icon)
 o isBorderPainted()
Returns whether the border should be painted.
 o isFocusPainted()
Returns whether focus should be painted.
 o isOpaque()
 o isRolloverEnabled()
Checks whether rollover effects are enabled.
 o isSelected()
Returns the state of the button.
 o paintBorder(Graphics)
Paint the button's border if BorderPainted property is true.
 o removeActionListener(ActionListener)
removes an ActionListener from the button
 o removeChangeListener(ChangeListener)
Removes a ChangeListener from the button.
 o removeItemListener(ItemListener)
removes an ItemListener from the button
 o setActionCommand(String)
Sets the action command for this button.
 o setBorderPainted(boolean)
Sets whether the border should be painted.
 o setDisabledIcon(Icon)
Sets the disabled icon for the button.
 o setDisabledSelectedIcon(Icon)
Sets the disabled selection icon for the button.
 o setEnabled(boolean)
Enables (or disables) the button.
 o setFocusPainted(boolean)
Sets whether focus should be painted.
 o setHorizontalAlignment(int)
Sets the horizontal alignment of the icon and text.
 o setHorizontalTextPosition(int)
Sets the horizontal position of the text relative to the icon.
 o setIcon(Icon)
Sets the button's default icon.
 o setKeyAccelerator(int)
Convenience to set the keyboard accelerator on the current model
 o setLabel(String)
Deprecated.
 o setMargin(Insets)
Sets space for margin between the button's border and the label.
 o setModel(ButtonModel)
Set the model that this button represents.
 o setOpaque(boolean)
If true the buttons background will be filled with the background color.
 o setPressedIcon(Icon)
Sets the pressed icon for the button.
 o setRolloverEnabled(boolean)
Sets whether rollover effects should be enabled.
 o setRolloverIcon(Icon)
Sets the rollover icon for the button.
 o setRolloverSelectedIcon(Icon)
Sets the rollover selected icon for the button.
 o setSelected(boolean)
Sets the state of the button.
 o setSelectedIcon(Icon)
Sets the selected icon for the button.
 o setText(String)
Sets the button's text.
 o setUI(ButtonUI)
Sets the button's UI.
 o setVerticalAlignment(int)
Sets the vertical alignment of the icon and text.
 o setVerticalTextPosition(int)
Sets the vertical position of the text relative to the icon.
 o updateUI()
Gets a new UI object from the default UIFactory.

Variables

 o model
 protected ButtonModel model
 o changeListener
 protected ChangeListener changeListener
The button's model listeners.

 o actionListener
 protected ActionListener actionListener
 o itemListener
 protected ItemListener itemListener
 o changeEvent
 protected transient ChangeEvent changeEvent
Only one ChangeEvent is needed per button instance since the event's only state is the source property. The source of events generated is always "this".

Constructors

 o AbstractButton
 public AbstractButton()

Methods

 o getText
 public String getText()
Returns the button's text.

See Also:
setText
 o setText
 public void setText(String text)
Sets the button's text.

Parameters:
t - the string used to set the text
See Also:
getText
 o isSelected
 public boolean isSelected()
Returns the state of the button. True if the radiobutton is selected, false if it's not.

 o setSelected
 public void setSelected(boolean b)
Sets the state of the button.

 o doClick
 public void doClick()
Programatically perform a "click". This does the same thing as if the user had pressed and released the button.

 o setMargin
 public void setMargin(Insets m)
Sets space for margin between the button's border and the label. Setting to null will cause the button to use the default margin. The button's default Border object will use this value to create the proper margin. However, if a non-default border is set on the button, it is that Border object's responsibility to create the appropriate margin space (else this property will effectively be ignored).

Parameters:
m - the space between the border and the label
 o getMargin
 public Insets getMargin()
Returns the margin between the button's border and the label.

 o getIcon
 public Icon getIcon()
Returns the default icon.

See Also:
setIcon
 o setIcon
 public void setIcon(Icon defaultIcon)
Sets the button's default icon. This icon is also used as the "pressed" and "disabled" icon if there is no explicitly set pressed icon.

Parameters:
g - the icon used as the default image
See Also:
getIcon, setPressedIcon
 o getPressedIcon
 public Icon getPressedIcon()
Returns the pressed icon for the button.

See Also:
setPressedIcon
 o setPressedIcon
 public void setPressedIcon(Icon pressedIcon)
Sets the pressed icon for the button.

Parameters:
g - the icon used as the "pressed" image
See Also:
getPressedIcon
 o getSelectedIcon
 public Icon getSelectedIcon()
Returns the selected icon for the button.

See Also:
setSelectedIcon
 o setSelectedIcon
 public void setSelectedIcon(Icon selectedIcon)
Sets the selected icon for the button.

Parameters:
g - the icon used as the "selected" image
See Also:
getSelectedIcon
 o getRolloverIcon
 public Icon getRolloverIcon()
Returns the rollover icon for the button.

See Also:
setRolloverIcon
 o setRolloverIcon
 public void setRolloverIcon(Icon rolloverIcon)
Sets the rollover icon for the button.

Parameters:
g - the icon used as the "rollover" image
See Also:
getRolloverIcon
 o getRolloverSelectedIcon
 public Icon getRolloverSelectedIcon()
Returns the rollover seletion icon for the button.

See Also:
setRolloverSelectedIcon
 o setRolloverSelectedIcon
 public void setRolloverSelectedIcon(Icon rolloverSelectedIcon)
Sets the rollover selected icon for the button.

Parameters:
g - the icon used as the "selected rollover" image
See Also:
getRolloverSelectedIcon
 o getDisabledIcon
 public Icon getDisabledIcon()
Returns the icon used by the button when it's disabled. If not no disabled icon has been set, the button constructs one from the default icon. PENDING(jeff): the disabled icon really should be created (if necesary) by the L&F.

See Also:
getPressedIcon, setDisabledIcon
 o setDisabledIcon
 public void setDisabledIcon(Icon disabledIcon)
Sets the disabled icon for the button.

Parameters:
g - the icon used as the disabled image
See Also:
getDisabledIcon
 o getDisabledSelectedIcon
 public Icon getDisabledSelectedIcon()
Returns the icon used by the button when it's disabled and selected. If not no disabled selection icon has been set, the button constructs one from the selection icon. PENDING(jeff): the disabled selection icon really should be created (if necesary) by the L&F.

See Also:
getPressedIcon, setDisabledIcon
 o setDisabledSelectedIcon
 public void setDisabledSelectedIcon(Icon disabledSelectedIcon)
Sets the disabled selection icon for the button.

Parameters:
g - the icon used as the disabled selection image
See Also:
getDisabledSelectedIcon
 o getVerticalAlignment
 public int getVerticalAlignment()
Returns the vertical alignment of the text and icon. Valid keys: CENTER (the default), TOP, BOTTOM

 o setVerticalAlignment
 public void setVerticalAlignment(int alignment)
Sets the vertical alignment of the icon and text. Valid keys: CENTER (the default), TOP, BOTTOM

 o getHorizontalAlignment
 public int getHorizontalAlignment()
Returns the horizontal alignment of the icon and text. Valid keys: CENTER (the default), LEFT, RIGHT

 o setHorizontalAlignment
 public void setHorizontalAlignment(int alignment)
Sets the horizontal alignment of the icon and text. Valid keys: CENTER (the default), LEFT, RIGHT

 o getVerticalTextPosition
 public int getVerticalTextPosition()
Returns the vertical position of the text relative to the icon Valid keys: CENTER (the default), TOP, BOTTOM

 o setVerticalTextPosition
 public void setVerticalTextPosition(int textPosition)
Sets the vertical position of the text relative to the icon. Valid keys: CENTER (the default), TOP, BOTTOM

 o getHorizontalTextPosition
 public int getHorizontalTextPosition()
Sets the horizontal position of the text relative to the icon. Valid keys: RIGHT (the default), LEFT, CENTER

 o setHorizontalTextPosition
 public void setHorizontalTextPosition(int textPosition)
Sets the horizontal position of the text relative to the icon. Valid keys: RIGHT (the default), LEFT, CENTER

 o checkHorizontalKey
 protected int checkHorizontalKey(int key,
                                  String exception)
Ensures that the key is a valid. Throws an IllegalArgument exception exception otherwise.

 o checkVerticalKey
 protected int checkVerticalKey(int key,
                                String exception)
Ensures that the key is a valid. Throws an IllegalArgument exception exception otherwise.

 o setActionCommand
 public void setActionCommand(String actionCommand)
Sets the action command for this button.

 o getActionCommand
 public String getActionCommand()
Returns the action command for this button.

 o isBorderPainted
 public boolean isBorderPainted()
Returns whether the border should be painted.

See Also:
setBorderPainted
 o setBorderPainted
 public void setBorderPainted(boolean b)
Sets whether the border should be painted.

Parameters:
b - if true and border property is not null, the border is painted.
See Also:
isBorderPainted
 o paintBorder
 protected void paintBorder(Graphics g)
Paint the button's border if BorderPainted property is true.

Overrides:
paintBorder in class JComponent
See Also:
paint, setBorder
 o isFocusPainted
 public boolean isFocusPainted()
Returns whether focus should be painted.

See Also:
setFocusPainted
 o setFocusPainted
 public void setFocusPainted(boolean b)
Sets whether focus should be painted.

Parameters:
b - if true, the focus state is painted.
See Also:
isFocusPainted
 o isRolloverEnabled
 public boolean isRolloverEnabled()
Checks whether rollover effects are enabled.

See Also:
setFocusPainted
 o setRolloverEnabled
 public void setRolloverEnabled(boolean b)
Sets whether rollover effects should be enabled.

Parameters:
b - if true, rollover effects should be painted.
See Also:
isRolloverEnabled
 o setOpaque
 public void setOpaque(boolean isOpaque)
If true the buttons background will be filled with the background color.

The default value of this property is true.

This is a JavaBeans bound property.

See Also:
isOpaque, getBackground
 o isOpaque
 public boolean isOpaque()
Returns:
The value of the opaque property.
Overrides:
isOpaque in class JComponent
See Also:
setOpaque
 o getKeyAccelerator
 public int getKeyAccelerator()
Convenience to get the keyboard accelerator from the the current model

 o setKeyAccelerator
 public void setKeyAccelerator(int keyAccelerator)
Convenience to set the keyboard accelerator on the current model

 o getModel
 public ButtonModel getModel()
Get the model that this button represents.

See Also:
setModel
 o setModel
 public void setModel(ButtonModel newModel)
Set the model that this button represents.

Parameters:
m - the Model
See Also:
getModel
 o getUI
 public ButtonUI getUI()
Returns the button's current UI.

See Also:
setUI
 o setUI
 public void setUI(ButtonUI ui)
Sets the button's UI.

Parameters:
ui - the new ButtonUI
See Also:
getUI
 o updateUI
 public void updateUI()
Gets a new UI object from the default UIFactory. Subtypes of AbstractButton should override this to update the UI. For example, JButton might do the following: setUI((ButtonUI)UIManager.getUI( "ButtonUI", "com.sun.java.swing.basic.BasicButtonUI", this));

Overrides:
updateUI in class JComponent
 o addChangeListener
 public void addChangeListener(ChangeListener l)
Adds a ChangeListener to the button.

 o removeChangeListener
 public void removeChangeListener(ChangeListener l)
Removes a ChangeListener from the button.

 o fireStateChanged
 protected void fireStateChanged()
 o addActionListener
 public void addActionListener(ActionListener l)
adds an ActionListener to the button

 o removeActionListener
 public void removeActionListener(ActionListener l)
removes an ActionListener from the button

 o createChangeListener
 protected ChangeListener createChangeListener()
Subclasses that want to handle ChangeEvents differently can override this to return another ChangeListener implementation.

 o fireActionPerformed
 protected void fireActionPerformed(ActionEvent event)
 o fireItemStateChanged
 protected void fireItemStateChanged(ItemEvent event)
 o createActionListener
 protected ActionListener createActionListener()
 o createItemListener
 protected ItemListener createItemListener()
 o setEnabled
 public void setEnabled(boolean b)
Enables (or disables) the button.

Overrides:
setEnabled in class Component
 o getLabel
 public String getLabel()
Note: getLabel() is deprecated. - Replaced by getText()

 o setLabel
 public void setLabel(String label)
Note: setLabel() is deprecated. - Replaced by setText(text)

 o addItemListener
 public void addItemListener(ItemListener l)
adds an ItemListener to the checkbox

 o removeItemListener
 public void removeItemListener(ItemListener l)
removes an ItemListener from the button

 o getSelectedObjects
 public Object[] getSelectedObjects()
 o init
 protected void init(String text,
                     Icon icon)
 o getAccessibleName
 public String getAccessibleName()
Get the accessible name of this object.

Returns:
the localized name of the object -- can be null if this object does not have a name
Overrides:
getAccessibleName in class JComponent
See Also:
setAccessibleName
 o getAccessibleStateSet
 public AccessibleStateSet getAccessibleStateSet()
Get the state set of this object.

Returns:
an instance of AccessibleState containing the current state of the object
Overrides:
getAccessibleStateSet in class JComponent
See Also:
AccessibleState

All Packages  Class Hierarchy  This Package  Previous  Next  Index