FileDocCategorySizeDatePackage
AbstractButton.javaAPI DocJava SE 5 API99601Fri Aug 26 14:57:52 BST 2005javax.swing

AbstractButton

public abstract class AbstractButton extends JComponent implements SwingConstants, ItemSelectable
Defines common behaviors for buttons and menu items. 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 JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}.

version
1.174 05/18/04
author
Jeff Dinkins

Fields Summary
public static final String
MODEL_CHANGED_PROPERTY
Identifies a change in the button model.
public static final String
TEXT_CHANGED_PROPERTY
Identifies a change in the button's text.
public static final String
MNEMONIC_CHANGED_PROPERTY
Identifies a change to the button's mnemonic.
public static final String
MARGIN_CHANGED_PROPERTY
Identifies a change in the button's margins.
public static final String
VERTICAL_ALIGNMENT_CHANGED_PROPERTY
Identifies a change in the button's vertical alignment.
public static final String
HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY
Identifies a change in the button's horizontal alignment.
public static final String
VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
Identifies a change in the button's vertical text position.
public static final String
HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY
Identifies a change in the button's horizontal text position.
public static final String
BORDER_PAINTED_CHANGED_PROPERTY
Identifies a change to having the border drawn, or having it not drawn.
public static final String
FOCUS_PAINTED_CHANGED_PROPERTY
Identifies a change to having the border highlighted when focused, or not.
public static final String
ROLLOVER_ENABLED_CHANGED_PROPERTY
Identifies a change from rollover enabled to disabled or back to enabled.
public static final String
CONTENT_AREA_FILLED_CHANGED_PROPERTY
Identifies a change to having the button paint the content area.
public static final String
ICON_CHANGED_PROPERTY
Identifies a change to the icon that represents the button.
public static final String
PRESSED_ICON_CHANGED_PROPERTY
Identifies a change to the icon used when the button has been pressed.
public static final String
SELECTED_ICON_CHANGED_PROPERTY
Identifies a change to the icon used when the button has been selected.
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.
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.
protected ButtonModel
model
The data model that determines the button's state.
private String
text
private Insets
margin
private Insets
defaultMargin
private Icon
defaultIcon
private Icon
pressedIcon
private Icon
disabledIcon
private Icon
selectedIcon
private Icon
disabledSelectedIcon
private Icon
rolloverIcon
private Icon
rolloverSelectedIcon
private boolean
paintBorder
private boolean
paintFocus
private boolean
rolloverEnabled
private boolean
contentAreaFilled
private int
verticalAlignment
private int
horizontalAlignment
private int
verticalTextPosition
private int
horizontalTextPosition
private int
iconTextGap
private int
mnemonic
private int
mnemonicIndex
private long
multiClickThreshhold
private boolean
borderPaintedSet
private boolean
rolloverEnabledSet
private boolean
iconTextGapSet
private boolean
contentAreaFilledSet
private boolean
setLayout
boolean
defaultCapable
private Handler
handler
Combined listeners: ActionListener, ChangeListener, ItemListener.
protected ChangeListener
changeListener
The button model's changeListener.
protected ActionListener
actionListener
The button model's ActionListener.
protected ItemListener
itemListener
The button model's ItemListener.
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".
private Action
action
private PropertyChangeListener
actionPropertyChangeListener
Constructors Summary
Methods Summary
public voidaddActionListener(java.awt.event.ActionListener l)
Adds an ActionListener to the button.

param
l the ActionListener to be added

        listenerList.add(ActionListener.class, l);
    
public voidaddChangeListener(javax.swing.event.ChangeListener l)
Adds a ChangeListener to the button.

param
l the listener to be added

        listenerList.add(ChangeListener.class, l);
    
protected voidaddImpl(java.awt.Component comp, java.lang.Object constraints, int index)
Adds the specified component to this container at the specified index, refer to {@link java.awt.Container#addImpl(Component, Object, int)} for a complete description of this method.

param
comp the component to be added
param
constraints an object expressing layout constraints for this component
param
index the position in the container's list at which to insert the component, where -1 means append to the end
exception
IllegalArgumentException if index is invalid
exception
IllegalArgumentException if adding the container's parent to itself
exception
IllegalArgumentException if adding a window to a container
since
1.5

        if (!setLayout) {
            setLayout(new OverlayLayout(this));
        }
        super.addImpl(comp, constraints, index);
    
public voidaddItemListener(java.awt.event.ItemListener l)
Adds an ItemListener to the checkbox.

param
l the ItemListener to be added

        listenerList.add(ItemListener.class, l);
    
protected intcheckHorizontalKey(int key, java.lang.String exception)
Verify that key is a legal value for the horizontalAlignment properties.

param
key the property value to check, one of the following values:
  • SwingConstants.RIGHT (the default)
  • SwingConstants.LEFT
  • SwingConstants.CENTER
  • SwingConstants.LEADING
  • SwingConstants.TRAILING
param
exception the IllegalArgumentException detail message
exception
IllegalArgumentException if key is not one of the legal values listed above
see
#setHorizontalTextPosition
see
#setHorizontalAlignment

        if ((key == LEFT) ||
            (key == CENTER) ||
            (key == RIGHT) ||
            (key == LEADING) ||
            (key == TRAILING)) {
            return key;
        } else {
            throw new IllegalArgumentException(exception);
        }
    
protected intcheckVerticalKey(int key, java.lang.String exception)
Ensures that the key is a valid. Throws an IllegalArgumentException exception otherwise.

param
key the value to check, one of the following values:
  • SwingConstants.CENTER (the default)
  • SwingConstants.TOP
  • SwingConstants.BOTTOM
param
exception a string to be passed to the IllegalArgumentException call if key is not one of the valid values listed above
exception
IllegalArgumentException if key is not one of the legal values listed above

        if ((key == TOP) || (key == CENTER) || (key == BOTTOM)) {
            return key;
        } else {
            throw new IllegalArgumentException(exception);
        }
    
protected voidconfigurePropertiesFromAction(javax.swing.Action a)
Factory method which sets the ActionEvent source's properties according to values from the Action instance. The properties which are set may differ for subclasses. By default, the properties which get set are Text, Icon, Enabled, ToolTipText, ActionCommand, and Mnemonic.

If the Action passed in is null, the following things will occur:

  • the text is set to null,
  • the icon is set to null,
  • enabled is set to true,
  • the tooltip text is set to null

param
a the Action from which to get the properties, or null
since
1.3
see
Action
see
#setAction

        configurePropertiesFromAction(a, null);
    
voidconfigurePropertiesFromAction(javax.swing.Action a, java.lang.String[] types)
Configures the AbstractButton's properties according to values from the Action instance. Which properties to set is determined by the types parameter. types may hold the following keys:
  • Action.NAME - set the Text property from the Action,
  • Action.SHORT_DESCRIPTION - set the ToolTipText property from the Action,
  • Action.SMALL_ICON - set the Icon property from the Action,
  • Action.MNEMONIC - set the Mnemonic property from the Action,
  • Action.ACTION_COMMAND_KEY - set the ActionCommand property from the Action,
  • "enabled" - set Enabled property from the Action

If the Action passed in is null, the following things will occur:

  • the text is set to null,
  • the icon is set to null,
  • enabled is set to true,
  • the tooltip text is set to null
  • the mnemonic is set to '\0'

param
a the Action from which to get the properties, or null
param
types determines which properties to set from the Action
since
1.4
see
Action
see
#setAction
see
#configurePropertiesFromAction(javax.swing.Action)

        if (types == null) {
            String[] alltypes = { Action.MNEMONIC_KEY, Action.NAME,
                                  Action.SHORT_DESCRIPTION, Action.SMALL_ICON,
                                  Action.ACTION_COMMAND_KEY, "enabled" };
            types = alltypes;
        }
        for (int i=0; i<types.length; i++) {
            String type = types[i];
            if (type == null) continue;

            if (type.equals(Action.MNEMONIC_KEY)) {
                Integer n = (a==null) ? null : (Integer)a.getValue(type);
                setMnemonic(n==null ? '\0" : n.intValue());
            } else if (type.equals(Action.NAME)) {
                // When hideActionText property is set, we don't use
                // Action name for button text. Useful for toolbar buttons.
                Boolean hide = (Boolean)getClientProperty("hideActionText");
                setText(a != null && hide!=Boolean.TRUE ?
                        (String)a.getValue(Action.NAME) :
                        null);
            } else if (type.equals(Action.SHORT_DESCRIPTION)) {
                setToolTipText(a!=null ? (String)a.getValue(type) : null);
            } else if (type.equals(Action.SMALL_ICON)) {
                setIcon(a!=null ? (Icon)a.getValue(type) : null);
            } else if (type.equals(Action.ACTION_COMMAND_KEY)) {
                setActionCommand(a!=null? (String)a.getValue(type) : null);
            } else if (type.equals("enabled")) {
                setEnabled(a!=null ? a.isEnabled() : true);
            }
        }
    
protected java.awt.event.ActionListenercreateActionListener()

        return getHandler();
    
protected java.beans.PropertyChangeListenercreateActionPropertyChangeListener(javax.swing.Action a)
Factory method which creates the PropertyChangeListener used to update the ActionEvent source as properties change on its Action instance. Subclasses may override this in order to provide their own PropertyChangeListener if the set of properties which should be kept up to date differs from the default properties (Text, Icon, Enabled, ToolTipText, Mnemonic).

Note that PropertyChangeListeners should avoid holding strong references to the ActionEvent source, as this may hinder garbage collection of the ActionEvent source and all components in its containment hierarchy.

param
a the new action for the button
since
1.3
see
Action
see
#setAction

        return new ButtonActionPropertyChangeListener(this, a);
    
protected javax.swing.event.ChangeListenercreateChangeListener()
Subclasses that want to handle ChangeEvents differently can override this to return another ChangeListener implementation.

return
the new ChangeListener

        return getHandler();
    
protected java.awt.event.ItemListenercreateItemListener()

        return getHandler();
    
public voiddoClick()
Programmatically perform a "click". This does the same thing as if the user had pressed and released the button.

        doClick(68);
    
public voiddoClick(int pressTime)
Programmatically perform a "click". This does the same thing as if the user had pressed and released the button. The button stays visually "pressed" for pressTime milliseconds.

param
pressTime the time to "hold down" the button, in milliseconds

        Dimension size = getSize();
        model.setArmed(true);
        model.setPressed(true);
        paintImmediately(new Rectangle(0,0, size.width, size.height));
        try {
            Thread.currentThread().sleep(pressTime);
        } catch(InterruptedException ie) {
        }
        model.setPressed(false);
        model.setArmed(false);
    
protected voidfireActionPerformed(java.awt.event.ActionEvent event)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the event parameter.

param
event the ActionEvent object
see
EventListenerList

        // Guaranteed to return a non-null array
        Object[] listeners = listenerList.getListenerList();
        ActionEvent e = null;
        // Process the listeners last to first, notifying
        // those that are interested in this event
        for (int i = listeners.length-2; i>=0; i-=2) {
            if (listeners[i]==ActionListener.class) {
                // Lazily create the event:
                if (e == null) {
                      String actionCommand = event.getActionCommand();
                      if(actionCommand == null) {
                         actionCommand = getActionCommand();
                      }
                      e = new ActionEvent(AbstractButton.this,
                                          ActionEvent.ACTION_PERFORMED,
                                          actionCommand,
                                          event.getWhen(),
                                          event.getModifiers());
                }
                ((ActionListener)listeners[i+1]).actionPerformed(e);
            }          
        }
    
protected voidfireItemStateChanged(java.awt.event.ItemEvent event)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the event parameter.

param
event the ItemEvent object
see
EventListenerList

        // Guaranteed to return a non-null array
        Object[] listeners = listenerList.getListenerList();
        ItemEvent e = null;
        // Process the listeners last to first, notifying
        // those that are interested in this event
        for (int i = listeners.length-2; i>=0; i-=2) {
            if (listeners[i]==ItemListener.class) {
                // Lazily create the event:
                if (e == null) {
                    e = new ItemEvent(AbstractButton.this,
                                      ItemEvent.ITEM_STATE_CHANGED,
                                      AbstractButton.this,
                                      event.getStateChange());
                }
                ((ItemListener)listeners[i+1]).itemStateChanged(e);
            }          
        }
	if (accessibleContext != null) {
	    if (event.getStateChange() == ItemEvent.SELECTED) {
		accessibleContext.firePropertyChange(
	            AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
                    null, AccessibleState.SELECTED);
		accessibleContext.firePropertyChange(
	            AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
                    new Integer(0), new Integer(1));
	    } else {
		accessibleContext.firePropertyChange(
	            AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
                    AccessibleState.SELECTED, null);
		accessibleContext.firePropertyChange(
	            AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
                    new Integer(1), new Integer(0));
	    }
	}   
    
protected voidfireStateChanged()
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created.

see
EventListenerList

        // Guaranteed to return a non-null array
        Object[] listeners = listenerList.getListenerList();
        // Process the listeners last to first, notifying
        // those that are interested in this event
        for (int i = listeners.length-2; i>=0; i-=2) {
            if (listeners[i]==ChangeListener.class) {
                // Lazily create the event:
                if (changeEvent == null)
                    changeEvent = new ChangeEvent(this);
                ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
            }          
        }
    
public javax.swing.ActiongetAction()
Returns the currently set Action for this ActionEvent source, or null if no Action is set.

return
the Action for this ActionEvent source, or null
since
1.3
see
Action
see
#setAction

	return action;
    
public java.lang.StringgetActionCommand()
Returns the action command for this button.

return
the action command for this button

        String ac = getModel().getActionCommand();
        if(ac == null) {
            ac = getText();
        }
        return ac;
    
public java.awt.event.ActionListener[]getActionListeners()
Returns an array of all the ActionListeners added to this AbstractButton with addActionListener().

return
all of the ActionListeners added or an empty array if no listeners have been added
since
1.4

        return (ActionListener[])(listenerList.getListeners(
            ActionListener.class));
    
public javax.swing.event.ChangeListener[]getChangeListeners()
Returns an array of all the ChangeListeners added to this AbstractButton with addChangeListener().

return
all of the ChangeListeners added or an empty array if no listeners have been added
since
1.4

        return (ChangeListener[])(listenerList.getListeners(
            ChangeListener.class));
    
public javax.swing.IcongetDisabledIcon()
Returns the icon used by the button when it's disabled. If no disabled icon has been set this will forward the call to the look and feel to construct an appropriate disabled Icon.

Some look and feels might not render the disabled Icon, in which case they will ignore this.

return
the disabledIcon property
see
#getPressedIcon
see
#setDisabledIcon
see
javax.swing.LookAndFeel#getDisabledIcon

        if (disabledIcon == null) {
            disabledIcon = UIManager.getLookAndFeel().getDisabledIcon(this, getIcon());
            if (disabledIcon != null) {
                firePropertyChange(DISABLED_ICON_CHANGED_PROPERTY, null, disabledIcon);
            }
        }
        return disabledIcon;
    
public javax.swing.IcongetDisabledSelectedIcon()
Returns the icon used by the button when it's disabled and selected. If no disabled selection icon has been set, this will forward the call to the LookAndFeel to construct an appropriate disabled Icon from the selection icon if it has been set and to getDisabledIcon() otherwise.

Some look and feels might not render the disabled selected Icon, in which case they will ignore this.

return
the disabledSelectedIcon property
see
#getDisabledIcon
see
#setDisabledSelectedIcon
see
javax.swing.LookAndFeel#getDisabledSelectedIcon

        if (disabledSelectedIcon == null) {
             if (selectedIcon != null) {
                 disabledSelectedIcon = UIManager.getLookAndFeel().
                         getDisabledSelectedIcon(this, getSelectedIcon());
             } else {
                 return getDisabledIcon();
             }
        }
        return disabledSelectedIcon;
    
public intgetDisplayedMnemonicIndex()
Returns the character, as an index, that the look and feel should provide decoration for as representing the mnemonic character.

since
1.4
return
index representing mnemonic character
see
#setDisplayedMnemonicIndex

        return mnemonicIndex;
    
private javax.swing.AbstractButton$HandlergetHandler()

        if (handler == null) {
            handler = new Handler();
        }
        return handler;
    
public intgetHorizontalAlignment()
Returns the horizontal alignment of the icon and text.

return
the horizontalAlignment property, one of the following values:
  • SwingConstants.RIGHT (the default)
  • SwingConstants.LEFT
  • SwingConstants.CENTER
  • SwingConstants.LEADING
  • SwingConstants.TRAILING

        return horizontalAlignment;
    
public intgetHorizontalTextPosition()
Returns the horizontal position of the text relative to the icon.

return
the horizontalTextPosition property, one of the following values:
  • SwingConstants.RIGHT
  • SwingConstants.LEFT
  • SwingConstants.CENTER
  • SwingConstants.LEADING
  • SwingConstants.TRAILING (the default)

        return horizontalTextPosition;
    
public javax.swing.IcongetIcon()
Returns the default icon.

return
the default Icon
see
#setIcon

        return defaultIcon;
    
public intgetIconTextGap()
Returns the amount of space between the text and the icon displayed in this button.

return
an int equal to the number of pixels between the text and the icon.
since
1.4
see
#setIconTextGap

        return iconTextGap;
    
public java.awt.event.ItemListener[]getItemListeners()
Returns an array of all the ItemListeners added to this AbstractButton with addItemListener().

return
all of the ItemListeners added or an empty array if no listeners have been added
since
1.4

        return (ItemListener[])listenerList.getListeners(ItemListener.class);
    
public java.lang.StringgetLabel()
Returns the label text.

return
a String containing the label
deprecated
- Replaced by getText

        return getText();
    
public java.awt.InsetsgetMargin()
Returns the margin between the button's border and the label.

return
an Insets object specifying the margin between the botton's border and the label
see
#setMargin

        return (margin == null) ? null : (Insets) margin.clone();
    
public intgetMnemonic()
Returns the keyboard mnemonic from the the current model.

return
the keyboard mnemonic from the model

        return mnemonic;
    
public javax.swing.ButtonModelgetModel()
Returns the model that this button represents.

return
the model property
see
#setModel

        return model;
    
public longgetMultiClickThreshhold()
Gets the amount of time (in milliseconds) required between mouse press events for the button to generate the corresponding action events.

see
#setMultiClickThreshhold
return
the amount of time required between mouse press events to generate corresponding action events
since
1.4

	return multiClickThreshhold;
    
public javax.swing.IcongetPressedIcon()
Returns the pressed icon for the button.

return
the pressedIcon property
see
#setPressedIcon

        return pressedIcon;
    
public javax.swing.IcongetRolloverIcon()
Returns the rollover icon for the button.

return
the rolloverIcon property
see
#setRolloverIcon

        return rolloverIcon;
    
public javax.swing.IcongetRolloverSelectedIcon()
Returns the rollover selection icon for the button.

return
the rolloverSelectedIcon property
see
#setRolloverSelectedIcon

        return rolloverSelectedIcon;
    
public javax.swing.IcongetSelectedIcon()
Returns the selected icon for the button.

return
the selectedIcon property
see
#setSelectedIcon

        return selectedIcon;
    
public java.lang.Object[]getSelectedObjects()
Returns an array (length 1) containing the label or null if the button is not selected.

return
an array containing 1 Object: the text of the button, if the item is selected; otherwise null

        if (isSelected() == false) {
            return null;
        }
        Object[] selectedObjects = new Object[1];
        selectedObjects[0] = getText();
        return selectedObjects;
    
public java.lang.StringgetText()
Returns the button's text.

return
the buttons text
see
#setText

    
                   
       
        return text;
    
public javax.swing.plaf.ButtonUIgetUI()
Returns the L&F object that renders this component.

return
the ButtonUI object
see
#setUI

        return (ButtonUI) ui;
    
public intgetVerticalAlignment()
Returns the vertical alignment of the text and icon.

return
the verticalAlignment property, one of the following values:
  • SwingConstants.CENTER (the default)
  • SwingConstants.TOP
  • SwingConstants.BOTTOM

        return verticalAlignment;
    
public intgetVerticalTextPosition()
Returns the vertical position of the text relative to the icon.

return
the verticalTextPosition property, one of the following values:
  • SwingConstants.CENTER (the default)
  • SwingConstants.TOP
  • SwingConstants.BOTTOM

        return verticalTextPosition;
    
public booleanimageUpdate(java.awt.Image img, int infoflags, int x, int y, int w, int h)
This is overridden to return false if the current Icon's Image is not equal to the passed in Image img.

param
img the Image to be compared
param
infoflags flags used to repaint the button when the image is updated and which determine how much is to be painted
param
x the x coordinate
param
y the y coordinate
param
w the width
param
h the height
see
java.awt.image.ImageObserver
see
java.awt.Component#imageUpdate(java.awt.Image, int, int, int, int, int)

        Icon iconDisplayed = getIcon();
        if (iconDisplayed == null) {
            return false;
        }

        if (!model.isEnabled()) {
            if (model.isSelected()) {
                iconDisplayed = getDisabledSelectedIcon();
            } else {
                iconDisplayed = getDisabledIcon();
            }
        } else if (model.isPressed() && model.isArmed()) {
            iconDisplayed = getPressedIcon();
        } else if (isRolloverEnabled() && model.isRollover()) {
            if (model.isSelected()) {
                iconDisplayed = getRolloverSelectedIcon();
            } else {
                iconDisplayed = getRolloverIcon();
            }
        } else if (model.isSelected()) {
            iconDisplayed = getSelectedIcon();
        }

 	if (!SwingUtilities.doesIconReferenceImage(iconDisplayed, img)) {
	    // We don't know about this image, disable the notification so
	    // we don't keep repainting.
	    return false;
	}
	return super.imageUpdate(img, infoflags, x, y, w, h);
    
protected voidinit(java.lang.String text, javax.swing.Icon icon)

        if(text != null) {
            setText(text);
        }
        
        if(icon != null) {
            setIcon(icon);
        }
        
        // Set the UI
        updateUI();

        setAlignmentX(LEFT_ALIGNMENT);
        setAlignmentY(CENTER_ALIGNMENT);
    
public booleanisBorderPainted()
Gets the borderPainted property.

return
the value of the borderPainted property
see
#setBorderPainted

        return paintBorder;
    
public booleanisContentAreaFilled()
Gets the contentAreaFilled property.

return
the contentAreaFilled property
see
#setContentAreaFilled

        return contentAreaFilled;
    
public booleanisFocusPainted()
Gets the paintFocus property.

return
the paintFocus property
see
#setFocusPainted

        return paintFocus;
    
private booleanisListener(java.lang.Class c, java.awt.event.ActionListener a)

	boolean isListener = false;
	Object[] listeners = listenerList.getListenerList();
        for (int i = listeners.length-2; i>=0; i-=2) {
            if (listeners[i]==c && listeners[i+1]==a) {
		    isListener=true;
	    }
	}
	return isListener;
    
public booleanisRolloverEnabled()
Gets the rolloverEnabled property.

return
the value of the rolloverEnabled property
see
#setRolloverEnabled

        return rolloverEnabled;
    
public booleanisSelected()
Returns the state of the button. True if the toggle button is selected, false if it's not.

return
true if the toggle button is selected, otherwise false

        return model.isSelected();
    
protected voidpaintBorder(java.awt.Graphics g)
Paint the button's border if BorderPainted property is true and the button has a border.

param
g the Graphics context in which to paint
see
#paint
see
#setBorder

    
        if (isBorderPainted()) {
            super.paintBorder(g);
        }
    
protected java.lang.StringparamString()
Returns a string representation of this AbstractButton. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Overriding paramString to provide information about the specific new aspects of the JFC components.

return
a string representation of this AbstractButton

	String defaultIconString = ((defaultIcon != null)
				    && (defaultIcon != this) ?
				    defaultIcon.toString() : "");
	String pressedIconString = ((pressedIcon != null)
				    && (pressedIcon != this) ?
				    pressedIcon.toString() : "");
	String disabledIconString = ((disabledIcon != null)
				     && (disabledIcon != this) ?
				     disabledIcon.toString() : "");
	String selectedIconString = ((selectedIcon != null)
				     && (selectedIcon != this) ?
				     selectedIcon.toString() : "");
	String disabledSelectedIconString = ((disabledSelectedIcon != null) &&
					     (disabledSelectedIcon != this) ?
					     disabledSelectedIcon.toString()
					     : "");
	String rolloverIconString = ((rolloverIcon != null)
				     && (rolloverIcon != this) ?
				     rolloverIcon.toString() : "");
	String rolloverSelectedIconString = ((rolloverSelectedIcon != null) &&
					     (rolloverSelectedIcon != this) ?
					     rolloverSelectedIcon.toString()
					     : "");
	String paintBorderString = (paintBorder ? "true" : "false");
	String paintFocusString = (paintFocus ? "true" : "false");
	String rolloverEnabledString = (rolloverEnabled ? "true" : "false");

	return super.paramString() +
	",defaultIcon=" + defaultIconString +
	",disabledIcon=" + disabledIconString +
	",disabledSelectedIcon=" + disabledSelectedIconString +
	",margin=" + margin +
	",paintBorder=" + paintBorderString +
	",paintFocus=" + paintFocusString +
	",pressedIcon=" + pressedIconString +
	",rolloverEnabled=" + rolloverEnabledString +
	",rolloverIcon=" + rolloverIconString +
	",rolloverSelectedIcon=" + rolloverSelectedIconString +
	",selectedIcon=" + selectedIconString +
	",text=" + text;
    
public voidremoveActionListener(java.awt.event.ActionListener l)
Removes an ActionListener from the button. If the listener is the currently set Action for the button, then the Action is set to null.

param
l the listener to be removed

	if ((l != null) && (getAction() == l)) {
	    setAction(null);
	} else {
	    listenerList.remove(ActionListener.class, l);
	}
    
public voidremoveChangeListener(javax.swing.event.ChangeListener l)
Removes a ChangeListener from the button.

param
l the listener to be removed

        listenerList.remove(ChangeListener.class, l);
    
public voidremoveItemListener(java.awt.event.ItemListener l)
Removes an ItemListener from the button.

param
l the ItemListener to be removed

        listenerList.remove(ItemListener.class, l);
    
public voidsetAction(javax.swing.Action a)
Sets the Action for the ActionEvent source. The new Action replaces any previously set Action but does not affect ActionListeners independently added with addActionListener. If the Action is already a registered ActionListener for the button, it is not re-registered.

A side-effect of setting the Action is that the ActionEvent source's properties are immediately set from the values in the Action (performed by the method configurePropertiesFromAction) and subsequently updated as the Action's properties change (via a PropertyChangeListener created by the method createActionPropertyChangeListener.

param
a the Action for the AbstractButton, or null
since
1.3
see
Action
see
#getAction
see
#configurePropertiesFromAction
see
#createActionPropertyChangeListener
beaninfo
bound: true attribute: visualUpdate true description: the Action instance connected with this ActionEvent source

	Action oldValue = getAction();
	if (action==null || !action.equals(a)) {
	    action = a;
	    if (oldValue!=null) {
		removeActionListener(oldValue);
		oldValue.removePropertyChangeListener(actionPropertyChangeListener);
		actionPropertyChangeListener = null;
	    }
	    configurePropertiesFromAction(action);
	    if (action!=null) {		
		// Don't add if it is already a listener
		if (!isListener(ActionListener.class, action)) {
		    addActionListener(action);
		}
		// Reverse linkage:
		actionPropertyChangeListener = createActionPropertyChangeListener(action);
		action.addPropertyChangeListener(actionPropertyChangeListener);
	    }
	    firePropertyChange("action", oldValue, action);
	    revalidate();
	    repaint();
	}
    
public voidsetActionCommand(java.lang.String actionCommand)
Sets the action command for this button.

param
actionCommand the action command for this button

        getModel().setActionCommand(actionCommand);
    
public voidsetBorderPainted(boolean b)
Sets the borderPainted property. If true and the button has a border, the border is painted. The default value for the borderPainted property is true.

param
b if true and border property is not null, the border is painted
see
#isBorderPainted
beaninfo
bound: true attribute: visualUpdate true description: Whether the border should be painted.

        boolean oldValue = paintBorder;
        paintBorder = b;
	borderPaintedSet = true;
        firePropertyChange(BORDER_PAINTED_CHANGED_PROPERTY, oldValue, paintBorder);
        if (b != oldValue) {
            revalidate();
            repaint();
        }
    
public voidsetContentAreaFilled(boolean b)
Sets the contentAreaFilled property. If true the button will paint the content area. If you wish to have a transparent button, such as an icon only button, for example, then you should set this to false. Do not call setOpaque(false). The default value for the the contentAreaFilled property is true.

This function may cause the component's opaque property to change.

The exact behavior of calling this function varies on a component-by-component and L&F-by-L&F basis.

param
b if true, the content should be filled; if false the content area is not filled
see
#isContentAreaFilled
see
#setOpaque
beaninfo
bound: true attribute: visualUpdate true description: Whether the button should paint the content area or leave it transparent.

        boolean oldValue = contentAreaFilled;
        contentAreaFilled = b;
	contentAreaFilledSet = true;
        firePropertyChange(CONTENT_AREA_FILLED_CHANGED_PROPERTY, oldValue, contentAreaFilled);
        if (b != oldValue) {
            repaint();
        }
    
public voidsetDisabledIcon(javax.swing.Icon disabledIcon)
Sets the disabled icon for the button.

param
disabledIcon the icon used as the disabled image
see
#getDisabledIcon
beaninfo
bound: true attribute: visualUpdate true description: The disabled icon for the button.

        Icon oldValue = this.disabledIcon;
        this.disabledIcon = disabledIcon;
        firePropertyChange(DISABLED_ICON_CHANGED_PROPERTY, oldValue, disabledIcon);
        if (accessibleContext != null) {
            accessibleContext.firePropertyChange(
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
                oldValue, disabledIcon);
        }
        if (disabledIcon != oldValue) {
            if (!isEnabled()) {
                repaint();
            }
        }
    
public voidsetDisabledSelectedIcon(javax.swing.Icon disabledSelectedIcon)
Sets the disabled selection icon for the button.

param
disabledSelectedIcon the icon used as the disabled selection image
see
#getDisabledSelectedIcon
beaninfo
bound: true attribute: visualUpdate true description: The disabled selection icon for the button.

        Icon oldValue = this.disabledSelectedIcon;
        this.disabledSelectedIcon = disabledSelectedIcon;
        firePropertyChange(DISABLED_SELECTED_ICON_CHANGED_PROPERTY, oldValue, disabledSelectedIcon);
        if (accessibleContext != null) {
            accessibleContext.firePropertyChange(
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
                oldValue, disabledSelectedIcon);
        }
        if (disabledSelectedIcon != oldValue) {
            if (disabledSelectedIcon == null || oldValue == null ||
                disabledSelectedIcon.getIconWidth() != oldValue.getIconWidth() ||
                disabledSelectedIcon.getIconHeight() != oldValue.getIconHeight()) {
                revalidate();
            } 
            if (!isEnabled() && isSelected()) {
                repaint();
            }
        }
    
public voidsetDisplayedMnemonicIndex(int index)
Provides a hint to the look and feel as to which character in the text should be decorated to represent the mnemonic. Not all look and feels may support this. A value of -1 indicates either there is no mnemonic, the mnemonic character is not contained in the string, or the developer does not wish the mnemonic to be displayed.

The value of this is updated as the properties relating to the mnemonic change (such as the mnemonic itself, the text...). You should only ever have to call this if you do not wish the default character to be underlined. For example, if the text was 'Save As', with a mnemonic of 'a', and you wanted the 'A' to be decorated, as 'Save As', you would have to invoke setDisplayedMnemonicIndex(5) after invoking setMnemonic(KeyEvent.VK_A).

since
1.4
param
index Index into the String to underline
exception
IllegalArgumentException will be thrown if index is >= length of the text, or < -1
see
#getDisplayedMnemonicIndex
beaninfo
bound: true attribute: visualUpdate true description: the index into the String to draw the keyboard character mnemonic at

        int oldValue = mnemonicIndex;
        if (index == -1) {
            mnemonicIndex = -1;
        } else {
            String text = getText();
            int textLength = (text == null) ? 0 : text.length();
            if (index < -1 || index >= textLength) {  // index out of range
                throw new IllegalArgumentException("index == " + index);
            }
        }
        mnemonicIndex = index;
        firePropertyChange("displayedMnemonicIndex", oldValue, index);
        if (index != oldValue) {
            revalidate();
            repaint();
        }
    
public voidsetEnabled(boolean b)
Enables (or disables) the button.

param
b true to enable the button, otherwise false

	if (!b && model.isRollover()) {
	    model.setRollover(false);
	} 
        super.setEnabled(b);
        model.setEnabled(b);
    
public voidsetFocusPainted(boolean b)
Sets the paintFocus property, which must be true for the focus state to be painted. The default value for the paintFocus property is true. Some look and feels might not paint focus state; they will ignore this property.

param
b if true, the focus state should be painted
see
#isFocusPainted
beaninfo
bound: true attribute: visualUpdate true description: Whether focus should be painted

        boolean oldValue = paintFocus;
        paintFocus = b;
        firePropertyChange(FOCUS_PAINTED_CHANGED_PROPERTY, oldValue, paintFocus);
        if (b != oldValue && isFocusOwner()) {
            revalidate();
            repaint();
        }
    
public voidsetHorizontalAlignment(int alignment)
Sets the horizontal alignment of the icon and text.

param
alignment one of the following values:
  • SwingConstants.RIGHT (the default)
  • SwingConstants.LEFT
  • SwingConstants.CENTER
  • SwingConstants.LEADING
  • SwingConstants.TRAILING
beaninfo
bound: true enum: LEFT SwingConstants.LEFT CENTER SwingConstants.CENTER RIGHT SwingConstants.RIGHT LEADING SwingConstants.LEADING TRAILING SwingConstants.TRAILING attribute: visualUpdate true description: The horizontal alignment of the icon and text.

        if (alignment == horizontalAlignment) return;
        int oldValue = horizontalAlignment;
        horizontalAlignment = checkHorizontalKey(alignment,
                                                 "horizontalAlignment");
        firePropertyChange(HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY,
                           oldValue, horizontalAlignment);       
        repaint();
    
public voidsetHorizontalTextPosition(int textPosition)
Sets the horizontal position of the text relative to the icon.

param
textPosition one of the following values:
  • SwingConstants.RIGHT
  • SwingConstants.LEFT
  • SwingConstants.CENTER
  • SwingConstants.LEADING
  • SwingConstants.TRAILING (the default)
exception
IllegalArgumentException if textPosition is not one of the legal values listed above
beaninfo
bound: true enum: LEFT SwingConstants.LEFT CENTER SwingConstants.CENTER RIGHT SwingConstants.RIGHT LEADING SwingConstants.LEADING TRAILING SwingConstants.TRAILING attribute: visualUpdate true description: The horizontal position of the text relative to the icon.

        if (textPosition == horizontalTextPosition) return;
        int oldValue = horizontalTextPosition;
        horizontalTextPosition = checkHorizontalKey(textPosition,
                                                    "horizontalTextPosition");
        firePropertyChange(HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY,
                           oldValue,
                           horizontalTextPosition);
        repaint();
    
public voidsetIcon(javax.swing.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.

param
defaultIcon the icon used as the default image
see
#getIcon
see
#setPressedIcon
beaninfo
bound: true attribute: visualUpdate true description: The button's default icon

        Icon oldValue = this.defaultIcon;
        this.defaultIcon = defaultIcon;

        /* If the default icon has really changed and we had
         * generated the disabled icon for this component,
         * (i.e. setDisabledIcon() was never called) then
         * clear the disabledIcon field.
         */
        if (defaultIcon != oldValue && (disabledIcon instanceof UIResource)) {
            disabledIcon = null;
        }

        firePropertyChange(ICON_CHANGED_PROPERTY, oldValue, defaultIcon);
        if (accessibleContext != null) {
            accessibleContext.firePropertyChange(
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
                oldValue, defaultIcon);
        }
        if (defaultIcon != oldValue) {
            if (defaultIcon == null || oldValue == null ||
                defaultIcon.getIconWidth() != oldValue.getIconWidth() ||
                defaultIcon.getIconHeight() != oldValue.getIconHeight()) {
                revalidate();
            } 
            repaint();
        }
    
public voidsetIconTextGap(int iconTextGap)
If both the icon and text properties are set, this property defines the space between them.

The default value of this property is 4 pixels.

This is a JavaBeans bound property.

since
1.4
see
#getIconTextGap
beaninfo
bound: true attribute: visualUpdate true description: If both the icon and text properties are set, this property defines the space between them.

        int oldValue = this.iconTextGap;
        this.iconTextGap = iconTextGap;
	iconTextGapSet = true;
        firePropertyChange("iconTextGap", oldValue, iconTextGap);
        if (iconTextGap != oldValue) {
            revalidate();
            repaint();
        }
    
public voidsetLabel(java.lang.String label)
Sets the label text.

param
label a String containing the text
deprecated
- Replaced by setText(text)
beaninfo
bound: true description: Replace by setText(text)

        setText(label);
    
public voidsetLayout(java.awt.LayoutManager mgr)
Sets the layout manager for this container, refer to {@link java.awt.Container#setLayout(LayoutManager)} for a complete description of this method.

param
mgr the specified layout manager
since
1.5

        setLayout = true;
        super.setLayout(mgr);
    
public voidsetMargin(java.awt.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).

param
m the space between the border and the label
beaninfo
bound: true attribute: visualUpdate true description: The space between the button's border and the label.

        // Cache the old margin if it comes from the UI
        if(m instanceof UIResource) {
            defaultMargin = m;
        } else if(margin instanceof UIResource) {
            defaultMargin = margin;
        }
            
        // If the client passes in a null insets, restore the margin
        // from the UI if possible
        if(m == null && defaultMargin != null) {
            m = defaultMargin;
        }

        Insets old = margin;
        margin = m;
        firePropertyChange(MARGIN_CHANGED_PROPERTY, old, m);
        if (old == null || !old.equals(m)) {
            revalidate();
            repaint();
        }
    
public voidsetMnemonic(int mnemonic)
Sets the keyboard mnemonic on the current model. The mnemonic is the key which when combined with the look and feel's mouseless modifier (usually Alt) will activate this button if focus is contained somewhere within this button's ancestor window.

A mnemonic must correspond to a single key on the keyboard and should be specified using one of the VK_XXX keycodes defined in java.awt.event.KeyEvent. Mnemonics are case-insensitive, therefore a key event with the corresponding keycode would cause the button to be activated whether or not the Shift modifier was pressed.

If the character defined by the mnemonic is found within the button's label string, the first occurrence of it will be underlined to indicate the mnemonic to the user.

param
mnemonic the key code which represents the mnemonic
see
java.awt.event.KeyEvent
see
#setDisplayedMnemonicIndex
beaninfo
bound: true attribute: visualUpdate true description: the keyboard character mnemonic

        int oldValue = getMnemonic();
        model.setMnemonic(mnemonic);
        updateMnemonicProperties();
    
public voidsetMnemonic(char mnemonic)
This method is now obsolete, please use setMnemonic(int) to set the mnemonic for a button. This method is only designed to handle character values which fall between 'a' and 'z' or 'A' and 'Z'.

param
mnemonic a char specifying the mnemonic value
see
#setMnemonic(int)
beaninfo
bound: true attribute: visualUpdate true description: the keyboard character mnemonic

        int vk = (int) mnemonic;
        if(vk >= 'a" && vk <='z")
            vk -= ('a" - 'A");
        setMnemonic(vk);
    
public voidsetModel(javax.swing.ButtonModel newModel)
Sets the model that this button represents.

param
newModel the new ButtonModel
see
#getModel
beaninfo
bound: true description: Model that the Button uses.

        
        ButtonModel oldModel = getModel();
        
        if (oldModel != null) {
            oldModel.removeChangeListener(changeListener);
            oldModel.removeActionListener(actionListener);
            oldModel.removeItemListener(itemListener);
            changeListener = null;
            actionListener = null;
            itemListener = null;
        }
        
        model = newModel;
        
        if (newModel != null) {
            changeListener = createChangeListener();
            actionListener = createActionListener();
            itemListener = createItemListener();
            newModel.addChangeListener(changeListener);
            newModel.addActionListener(actionListener);
            newModel.addItemListener(itemListener);

            mnemonic = newModel.getMnemonic();
        } else {
            mnemonic = '\0";
        }

        updateDisplayedMnemonicIndex(getText(), mnemonic);

        firePropertyChange(MODEL_CHANGED_PROPERTY, oldModel, newModel);
        if (newModel != oldModel) {
            revalidate();
            repaint();
        }
    
public voidsetMultiClickThreshhold(long threshhold)
Sets the amount of time (in milliseconds) required between mouse press events for the button to generate the corresponding action events. After the initial mouse press occurs (and action event generated) any subsequent mouse press events which occur on intervals less than the threshhold will be ignored and no corresponding action event generated. By default the threshhold is 0, which means that for each mouse press, an action event will be fired, no matter how quickly the mouse clicks occur. In buttons where this behavior is not desirable (for example, the "OK" button in a dialog), this threshhold should be set to an appropriate positive value.

see
#getMultiClickThreshhold
param
threshhold the amount of time required between mouse press events to generate corresponding action events
exception
IllegalArgumentException if threshhold < 0
since
1.4

	if (threshhold < 0) {
	    throw new IllegalArgumentException("threshhold must be >= 0");
	}
	this.multiClickThreshhold = threshhold;
    
public voidsetPressedIcon(javax.swing.Icon pressedIcon)
Sets the pressed icon for the button.

param
pressedIcon the icon used as the "pressed" image
see
#getPressedIcon
beaninfo
bound: true attribute: visualUpdate true description: The pressed icon for the button.

        Icon oldValue = this.pressedIcon;
        this.pressedIcon = pressedIcon;
        firePropertyChange(PRESSED_ICON_CHANGED_PROPERTY, oldValue, pressedIcon);
        if (accessibleContext != null) {
            accessibleContext.firePropertyChange(
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
                oldValue, pressedIcon);
        }
        if (pressedIcon != oldValue) {
            if (getModel().isPressed()) {
                repaint();
            }
        }
    
public voidsetRolloverEnabled(boolean b)
Sets the rolloverEnabled property, which must be true for rollover effects to occur. The default value for the rolloverEnabled property is false. Some look and feels might not implement rollover effects; they will ignore this property.

param
b if true, rollover effects should be painted
see
#isRolloverEnabled
beaninfo
bound: true attribute: visualUpdate true description: Whether rollover effects should be enabled.

        boolean oldValue = rolloverEnabled;
        rolloverEnabled = b;
        rolloverEnabledSet = true;
        firePropertyChange(ROLLOVER_ENABLED_CHANGED_PROPERTY, oldValue, rolloverEnabled);
        if (b != oldValue) {
            repaint();
        }
    
public voidsetRolloverIcon(javax.swing.Icon rolloverIcon)
Sets the rollover icon for the button.

param
rolloverIcon the icon used as the "rollover" image
see
#getRolloverIcon
beaninfo
bound: true attribute: visualUpdate true description: The rollover icon for the button.

        Icon oldValue = this.rolloverIcon;
        this.rolloverIcon = rolloverIcon;
        firePropertyChange(ROLLOVER_ICON_CHANGED_PROPERTY, oldValue, rolloverIcon);
        if (accessibleContext != null) {
            accessibleContext.firePropertyChange(
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
                oldValue, rolloverIcon);
        }
        setRolloverEnabled(true);
        if (rolloverIcon != oldValue) {
            // No way to determine whether we are currently in
            // a rollover state, so repaint regardless
            repaint();
        }
      
    
public voidsetRolloverSelectedIcon(javax.swing.Icon rolloverSelectedIcon)
Sets the rollover selected icon for the button.

param
rolloverSelectedIcon the icon used as the "selected rollover" image
see
#getRolloverSelectedIcon
beaninfo
bound: true attribute: visualUpdate true description: The rollover selected icon for the button.

        Icon oldValue = this.rolloverSelectedIcon;
        this.rolloverSelectedIcon = rolloverSelectedIcon;
        firePropertyChange(ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, oldValue, rolloverSelectedIcon);
        if (accessibleContext != null) {
            accessibleContext.firePropertyChange(
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
                oldValue, rolloverSelectedIcon);
        }
        setRolloverEnabled(true);
        if (rolloverSelectedIcon != oldValue) {
            // No way to determine whether we are currently in
            // a rollover state, so repaint regardless
            if (isSelected()) {
                repaint();
            }
        }
    
public voidsetSelected(boolean b)
Sets the state of the button. Note that this method does not trigger an actionEvent. Call doClick to perform a programatic action change.

param
b true if the button is selected, otherwise false

        boolean oldValue = isSelected();

        // TIGER - 4840653
        // Removed code which fired an AccessibleState.SELECTED
        // PropertyChangeEvent since this resulted in two
        // identical events being fired since
        // AbstractButton.fireItemStateChanged also fires the
        // same event. This caused screen readers to speak the
        // name of the item twice.

        model.setSelected(b);
    
public voidsetSelectedIcon(javax.swing.Icon selectedIcon)
Sets the selected icon for the button.

param
selectedIcon the icon used as the "selected" image
see
#getSelectedIcon
beaninfo
bound: true attribute: visualUpdate true description: The selected icon for the button.

        Icon oldValue = this.selectedIcon;
        this.selectedIcon = selectedIcon;

        /* If the default selected icon has really changed and we had
         * generated the disabled selected icon for this component,
         * (i.e. setDisabledSelectedIcon() was never called) then
         * clear the disabledSelectedIcon field.
         */
        if (selectedIcon != oldValue &&
            disabledSelectedIcon instanceof UIResource) {

            disabledSelectedIcon = null;
        }

        firePropertyChange(SELECTED_ICON_CHANGED_PROPERTY, oldValue, selectedIcon);
        if (accessibleContext != null) {
            accessibleContext.firePropertyChange(
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
                oldValue, selectedIcon);
        }
        if (selectedIcon != oldValue) {
            if (isSelected()) {
                repaint();
            }
        }
    
public voidsetText(java.lang.String text)
Sets the button's text.

param
text the string used to set the text
see
#getText
beaninfo
bound: true preferred: true attribute: visualUpdate true description: The button's text.

        String oldValue = this.text;
        this.text = text;
        firePropertyChange(TEXT_CHANGED_PROPERTY, oldValue, text);
        updateDisplayedMnemonicIndex(text, getMnemonic());

        if (accessibleContext != null) {
            accessibleContext.firePropertyChange(
                AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
                oldValue, text);
        }
        if (text == null || oldValue == null || !text.equals(oldValue)) {
            revalidate();
            repaint();
        }
    
public voidsetUI(javax.swing.plaf.ButtonUI ui)
Sets the L&F object that renders this component.

param
ui the ButtonUI L&F object
see
#getUI
beaninfo
bound: true hidden: true attribute: visualUpdate true description: The UI object that implements the LookAndFeel.

        super.setUI(ui);
        // disabled icons are generated by the LF so they should be unset here
        if (disabledIcon instanceof UIResource) {
            setDisabledIcon(null);
        }
        if (disabledSelectedIcon instanceof UIResource) {
            setDisabledSelectedIcon(null);
        }
    
voidsetUIProperty(java.lang.String propertyName, java.lang.Object value)

        if (propertyName == "borderPainted") {
	    if (!borderPaintedSet) {
		setBorderPainted(((Boolean)value).booleanValue());
		borderPaintedSet = false;
	    }
	} else if (propertyName == "rolloverEnabled") {
	    if (!rolloverEnabledSet) {
		setRolloverEnabled(((Boolean)value).booleanValue());
		rolloverEnabledSet = false;
	    }
	} else if (propertyName == "iconTextGap") {
	    if (!iconTextGapSet) {
		setIconTextGap(((Number)value).intValue());
		iconTextGapSet = false;
	    }
	} else if (propertyName == "contentAreaFilled") {
	    if (!contentAreaFilledSet) {
		setContentAreaFilled(((Boolean)value).booleanValue());
		contentAreaFilledSet = false;
	    }
	} else {
	    super.setUIProperty(propertyName, value);
	}
    
public voidsetVerticalAlignment(int alignment)
Sets the vertical alignment of the icon and text.

param
alignment one of the following values:
  • SwingConstants.CENTER (the default)
  • SwingConstants.TOP
  • SwingConstants.BOTTOM
beaninfo
bound: true enum: TOP SwingConstants.TOP CENTER SwingConstants.CENTER BOTTOM SwingConstants.BOTTOM attribute: visualUpdate true description: The vertical alignment of the icon and text.

        if (alignment == verticalAlignment) return;
        int oldValue = verticalAlignment;
        verticalAlignment = checkVerticalKey(alignment, "verticalAlignment");
        firePropertyChange(VERTICAL_ALIGNMENT_CHANGED_PROPERTY, oldValue, verticalAlignment);         repaint();
    
public voidsetVerticalTextPosition(int textPosition)
Sets the vertical position of the text relative to the icon.

param
textPosition one of the following values:
  • SwingConstants.CENTER (the default)
  • SwingConstants.TOP
  • SwingConstants.BOTTOM
beaninfo
bound: true enum: TOP SwingConstants.TOP CENTER SwingConstants.CENTER BOTTOM SwingConstants.BOTTOM attribute: visualUpdate true description: The vertical position of the text relative to the icon.

        if (textPosition == verticalTextPosition) return;
        int oldValue = verticalTextPosition;
        verticalTextPosition = checkVerticalKey(textPosition, "verticalTextPosition");
        firePropertyChange(VERTICAL_TEXT_POSITION_CHANGED_PROPERTY, oldValue, verticalTextPosition);
        repaint();
    
private voidupdateDisplayedMnemonicIndex(java.lang.String text, int mnemonic)
Update the displayedMnemonicIndex property. This method is called when either text or mnemonic changes. The new value of the displayedMnemonicIndex property is the index of the first occurrence of mnemonic in text.

        setDisplayedMnemonicIndex(
            SwingUtilities.findDisplayedMnemonicIndex(text, mnemonic));
    
private voidupdateMnemonicProperties()
Brings the mnemonic property in accordance with model's mnemonic. This is called when model's mnemonic changes. Also updates the displayedMnemonicIndex property.

        int newMnemonic = model.getMnemonic();
        if (mnemonic != newMnemonic) {
            int oldValue = mnemonic;
            mnemonic = newMnemonic;
            firePropertyChange(MNEMONIC_CHANGED_PROPERTY,
                               oldValue, mnemonic);
            updateDisplayedMnemonicIndex(getText(), mnemonic);
            revalidate();
            repaint();
        }
    
public voidupdateUI()
Resets the UI property to a value from the current look and feel. Subtypes of AbstractButton should override this to update the UI. For example, JButton might do the following:
setUI((ButtonUI)UIManager.getUI(
"ButtonUI", "javax.swing.plaf.basic.BasicButtonUI", this));