Methods Summary |
---|
protected void | actionPropertyChanged(javax.swing.Action action, java.lang.String propertyName)Updates the button's state in response to property changes in the
associated action. This method is invoked from the
{@code PropertyChangeListener} returned from
{@code createActionPropertyChangeListener}. Subclasses do not normally
need to invoke this. Subclasses that support additional {@code Action}
properties should override this and
{@code configurePropertiesFromAction}.
Refer to the table at
Swing Components Supporting Action for a list of
the properties this method sets.
if (propertyName == Action.NAME) {
setTextFromAction(action, true);
} else if (propertyName == "enabled") {
AbstractAction.setEnabledFromAction(this, action);
} else if (propertyName == Action.SHORT_DESCRIPTION) {
AbstractAction.setToolTipTextFromAction(this, action);
} else if (propertyName == Action.SMALL_ICON) {
smallIconChanged(action);
} else if (propertyName == Action.MNEMONIC_KEY) {
setMnemonicFromAction(action);
} else if (propertyName == Action.ACTION_COMMAND_KEY) {
setActionCommandFromAction(action);
} else if (propertyName == Action.SELECTED_KEY &&
AbstractAction.hasSelectedKey(action) &&
shouldUpdateSelectedStateFromAction()) {
setSelectedFromAction(action);
} else if (propertyName == Action.DISPLAYED_MNEMONIC_INDEX_KEY) {
setDisplayedMnemonicIndexFromAction(action, true);
} else if (propertyName == Action.LARGE_ICON_KEY) {
largeIconChanged(action);
}
|
public void | addActionListener(java.awt.event.ActionListener l)Adds an ActionListener to the button.
listenerList.add(ActionListener.class, l);
|
public void | addChangeListener(javax.swing.event.ChangeListener l)Adds a ChangeListener to the button.
listenerList.add(ChangeListener.class, l);
|
protected void | addImpl(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.
if (!setLayout) {
setLayout(new OverlayLayout(this));
}
super.addImpl(comp, constraints, index);
|
public void | addItemListener(java.awt.event.ItemListener l)Adds an ItemListener to the checkbox .
listenerList.add(ItemListener.class, l);
|
protected int | checkHorizontalKey(int key, java.lang.String exception)Verify that the {@code key} argument is a legal value for the
{@code horizontalAlignment} and {@code horizontalTextPosition}
properties. Valid values are:
- {@code SwingConstants.RIGHT}
- {@code SwingConstants.LEFT}
- {@code SwingConstants.CENTER}
- {@code SwingConstants.LEADING}
- {@code SwingConstants.TRAILING}
if ((key == LEFT) ||
(key == CENTER) ||
(key == RIGHT) ||
(key == LEADING) ||
(key == TRAILING)) {
return key;
} else {
throw new IllegalArgumentException(exception);
}
|
protected int | checkVerticalKey(int key, java.lang.String exception)Verify that the {@code key} argument is a legal value for the
vertical properties. Valid values are:
- {@code SwingConstants.CENTER}
- {@code SwingConstants.TOP}
- {@code SwingConstants.BOTTOM}
if ((key == TOP) || (key == CENTER) || (key == BOTTOM)) {
return key;
} else {
throw new IllegalArgumentException(exception);
}
|
void | clientPropertyChanged(java.lang.Object key, java.lang.Object oldValue, java.lang.Object newValue)
if (key == "hideActionText") {
boolean current = (newValue instanceof Boolean) ?
(Boolean)newValue : false;
if (getHideActionText() != current) {
setHideActionText(current);
}
}
|
protected void | configurePropertiesFromAction(javax.swing.Action a)Sets the properties on this button to match those in the specified
Action . Refer to
Swing Components Supporting Action for more
details as to which properties this sets.
setMnemonicFromAction(a);
setTextFromAction(a, false);
AbstractAction.setToolTipTextFromAction(this, a);
setIconFromAction(a);
setActionCommandFromAction(a);
AbstractAction.setEnabledFromAction(this, a);
if (AbstractAction.hasSelectedKey(a) &&
shouldUpdateSelectedStateFromAction()) {
setSelectedFromAction(a);
}
setDisplayedMnemonicIndexFromAction(a, false);
|
protected java.awt.event.ActionListener | createActionListener()
return getHandler();
|
protected java.beans.PropertyChangeListener | createActionPropertyChangeListener(javax.swing.Action a)Creates and returns a PropertyChangeListener that is
responsible for listening for changes from the specified
Action and updating the appropriate properties.
Warning: If you subclass this do not create an anonymous
inner class. If you do the lifetime of the button will be tied to
that of the Action .
return createActionPropertyChangeListener0(a);
|
java.beans.PropertyChangeListener | createActionPropertyChangeListener0(javax.swing.Action a)
return new ButtonActionPropertyChangeListener(this, a);
|
protected javax.swing.event.ChangeListener | createChangeListener()Subclasses that want to handle ChangeEvents differently
can override this to return another ChangeListener
implementation.
return getHandler();
|
protected java.awt.event.ItemListener | createItemListener()
return getHandler();
|
public void | doClick()Programmatically perform a "click". This does the same
thing as if the user had pressed and released the button.
doClick(68);
|
public void | doClick(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.
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 void | fireActionPerformed(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.
// 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 void | fireItemStateChanged(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.
// 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 void | fireStateChanged()Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created.
// 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.Action | getAction()Returns the currently set Action for this
ActionEvent source, or null
if no Action is set.
return action;
|
public java.lang.String | getActionCommand()Returns 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 ActionListener s added
to this AbstractButton with addActionListener().
return (ActionListener[])(listenerList.getListeners(
ActionListener.class));
|
public javax.swing.event.ChangeListener[] | getChangeListeners()Returns an array of all the ChangeListener s added
to this AbstractButton with addChangeListener().
return (ChangeListener[])(listenerList.getListeners(
ChangeListener.class));
|
public javax.swing.Icon | getDisabledIcon()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.
if (disabledIcon == null) {
disabledIcon = UIManager.getLookAndFeel().getDisabledIcon(this, getIcon());
if (disabledIcon != null) {
firePropertyChange(DISABLED_ICON_CHANGED_PROPERTY, null, disabledIcon);
}
}
return disabledIcon;
|
public javax.swing.Icon | getDisabledSelectedIcon()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.
if (disabledSelectedIcon == null) {
if (selectedIcon != null) {
disabledSelectedIcon = UIManager.getLookAndFeel().
getDisabledSelectedIcon(this, getSelectedIcon());
} else {
return getDisabledIcon();
}
}
return disabledSelectedIcon;
|
public int | getDisplayedMnemonicIndex()Returns the character, as an index, that the look and feel should
provide decoration for as representing the mnemonic character.
return mnemonicIndex;
|
private javax.swing.AbstractButton$Handler | getHandler()
if (handler == null) {
handler = new Handler();
}
return handler;
|
public boolean | getHideActionText()Returns the value of the hideActionText property, which
determines whether the button displays text from the
Action . This is useful only if an Action
has been installed on the button.
return hideActionText;
|
public int | getHorizontalAlignment()Returns the horizontal alignment of the icon and text.
{@code AbstractButton}'s default is {@code SwingConstants.CENTER},
but subclasses such as {@code JCheckBox} may use a different default.
return horizontalAlignment;
|
public int | getHorizontalTextPosition()Returns the horizontal position of the text relative to the icon.
return horizontalTextPosition;
|
public javax.swing.Icon | getIcon()Returns the default icon.
return defaultIcon;
|
public int | getIconTextGap()Returns the amount of space between the text and the icon
displayed in this button.
return iconTextGap;
|
public java.awt.event.ItemListener[] | getItemListeners()Returns an array of all the ItemListener s added
to this AbstractButton with addItemListener().
return (ItemListener[])listenerList.getListeners(ItemListener.class);
|
public java.lang.String | getLabel()Returns the label text.
return getText();
|
public java.awt.Insets | getMargin()Returns the margin between the button's border and
the label.
return (margin == null) ? null : (Insets) margin.clone();
|
public int | getMnemonic()Returns the keyboard mnemonic from the the current model.
return mnemonic;
|
public javax.swing.ButtonModel | getModel()Returns the model that this button represents.
return model;
|
public long | getMultiClickThreshhold()Gets the amount of time (in milliseconds) required between
mouse press events for the button to generate the corresponding
action events.
return multiClickThreshhold;
|
public javax.swing.Icon | getPressedIcon()Returns the pressed icon for the button.
return pressedIcon;
|
public javax.swing.Icon | getRolloverIcon()Returns the rollover icon for the button.
return rolloverIcon;
|
public javax.swing.Icon | getRolloverSelectedIcon()Returns the rollover selection icon for the button.
return rolloverSelectedIcon;
|
public javax.swing.Icon | getSelectedIcon()Returns the selected icon for the button.
return selectedIcon;
|
public java.lang.Object[] | getSelectedObjects()Returns an array (length 1) containing the label or
null if the button is not selected.
if (isSelected() == false) {
return null;
}
Object[] selectedObjects = new Object[1];
selectedObjects[0] = getText();
return selectedObjects;
|
public java.lang.String | getText()Returns the button's text.
return text;
|
public javax.swing.plaf.ButtonUI | getUI()Returns the L&F object that renders this component.
return (ButtonUI) ui;
|
public int | getVerticalAlignment()Returns the vertical alignment of the text and icon.
return verticalAlignment;
|
public int | getVerticalTextPosition()Returns the vertical position of the text relative to the icon.
return verticalTextPosition;
|
public boolean | imageUpdate(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 .
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 void | init(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 boolean | isBorderPainted()Gets the borderPainted property.
return paintBorder;
|
public boolean | isContentAreaFilled()Gets the contentAreaFilled property.
return contentAreaFilled;
|
public boolean | isFocusPainted()Gets the paintFocus property.
return paintFocus;
|
private boolean | isListener(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 boolean | isRolloverEnabled()Gets the rolloverEnabled property.
return rolloverEnabled;
|
public boolean | isSelected()Returns the state of the button. True if the
toggle button is selected, false if it's not.
return model.isSelected();
|
void | largeIconChanged(javax.swing.Action a)
setIconFromAction(a);
|
protected void | paintBorder(java.awt.Graphics g)Paint the button's border if BorderPainted
property is true and the button has a border.
if (isBorderPainted()) {
super.paintBorder(g);
}
|
protected java.lang.String | paramString()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.
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 void | removeActionListener(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 .
if ((l != null) && (getAction() == l)) {
setAction(null);
} else {
listenerList.remove(ActionListener.class, l);
}
|
public void | removeChangeListener(javax.swing.event.ChangeListener l)Removes a ChangeListener from the button.
listenerList.remove(ChangeListener.class, l);
|
public void | removeItemListener(java.awt.event.ItemListener l)Removes an ItemListener from the button.
listenerList.remove(ItemListener.class, l);
|
public void | removeNotify(){@inheritDoc}
super.removeNotify();
if(isRolloverEnabled()) {
getModel().setRollover(false);
}
|
public void | setAction(javax.swing.Action a)Sets the Action .
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.
Setting the Action results in immediately changing
all the properties described in
Swing Components Supporting Action .
Subsequently, the button's properties are automatically updated
as the Action 's properties change.
This method uses three other methods to set
and help track the Action 's property values.
It uses the configurePropertiesFromAction method
to immediately change the button's properties.
To track changes in the Action 's property values,
this method registers the PropertyChangeListener
returned by createActionPropertyChangeListener . The
default {@code PropertyChangeListener} invokes the
{@code actionPropertyChanged} method when a property in the
{@code Action} changes.
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);
}
|
public void | setActionCommand(java.lang.String actionCommand)Sets the action command for this button.
getModel().setActionCommand(actionCommand);
|
private void | setActionCommandFromAction(javax.swing.Action a)
setActionCommand((a != null) ?
(String)a.getValue(Action.ACTION_COMMAND_KEY) :
null);
|
public void | setBorderPainted(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 .
boolean oldValue = paintBorder;
paintBorder = b;
borderPaintedSet = true;
firePropertyChange(BORDER_PAINTED_CHANGED_PROPERTY, oldValue, paintBorder);
if (b != oldValue) {
revalidate();
repaint();
}
|
public void | setContentAreaFilled(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.
boolean oldValue = contentAreaFilled;
contentAreaFilled = b;
contentAreaFilledSet = true;
firePropertyChange(CONTENT_AREA_FILLED_CHANGED_PROPERTY, oldValue, contentAreaFilled);
if (b != oldValue) {
repaint();
}
|
public void | setDisabledIcon(javax.swing.Icon disabledIcon)Sets 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 void | setDisabledSelectedIcon(javax.swing.Icon disabledSelectedIcon)Sets 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 void | setDisplayedMnemonicIndex(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) .
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();
}
|
private void | setDisplayedMnemonicIndexFromAction(javax.swing.Action a, boolean fromPropertyChange)
Integer iValue = (a == null) ? null :
(Integer)a.getValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY);
if (fromPropertyChange || iValue != null) {
int value;
if (iValue == null) {
value = -1;
} else {
value = iValue;
String text = getText();
if (text == null || value >= text.length()) {
value = -1;
}
}
setDisplayedMnemonicIndex(value);
}
|
public void | setEnabled(boolean b)Enables (or disables) the button.
if (!b && model.isRollover()) {
model.setRollover(false);
}
super.setEnabled(b);
model.setEnabled(b);
|
public void | setFocusPainted(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.
boolean oldValue = paintFocus;
paintFocus = b;
firePropertyChange(FOCUS_PAINTED_CHANGED_PROPERTY, oldValue, paintFocus);
if (b != oldValue && isFocusOwner()) {
revalidate();
repaint();
}
|
public void | setHideActionText(boolean hideActionText)Sets the hideActionText property, which determines
whether the button displays text from the Action .
This is useful only if an Action has been
installed on the button.
if (hideActionText != this.hideActionText) {
this.hideActionText = hideActionText;
if (getAction() != null) {
setTextFromAction(getAction(), false);
}
firePropertyChange("hideActionText", !hideActionText,
hideActionText);
}
|
public void | setHorizontalAlignment(int alignment)Sets the horizontal alignment of the icon and text.
{@code AbstractButton}'s default is {@code SwingConstants.CENTER},
but subclasses such as {@code JCheckBox} may use a different default.
if (alignment == horizontalAlignment) return;
int oldValue = horizontalAlignment;
horizontalAlignment = checkHorizontalKey(alignment,
"horizontalAlignment");
firePropertyChange(HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY,
oldValue, horizontalAlignment);
repaint();
|
public void | setHorizontalTextPosition(int textPosition)Sets 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);
revalidate();
repaint();
|
public void | setIcon(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.
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();
}
|
void | setIconFromAction(javax.swing.Action a)
Icon icon = null;
if (a != null) {
icon = (Icon)a.getValue(Action.LARGE_ICON_KEY);
if (icon == null) {
icon = (Icon)a.getValue(Action.SMALL_ICON);
}
}
setIcon(icon);
|
public void | setIconTextGap(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.
int oldValue = this.iconTextGap;
this.iconTextGap = iconTextGap;
iconTextGapSet = true;
firePropertyChange("iconTextGap", oldValue, iconTextGap);
if (iconTextGap != oldValue) {
revalidate();
repaint();
}
|
public void | setLabel(java.lang.String label)Sets the label text.
setText(label);
|
public void | setLayout(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.
setLayout = true;
super.setLayout(mgr);
|
public void | setMargin(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).
// 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 void | setMnemonic(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.
int oldValue = getMnemonic();
model.setMnemonic(mnemonic);
updateMnemonicProperties();
|
public void | setMnemonic(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'.
int vk = (int) mnemonic;
if(vk >= 'a" && vk <='z")
vk -= ('a" - 'A");
setMnemonic(vk);
|
private void | setMnemonicFromAction(javax.swing.Action a)
Integer n = (a == null) ? null :
(Integer)a.getValue(Action.MNEMONIC_KEY);
setMnemonic((n == null) ? '\0" : n);
|
public void | setModel(javax.swing.ButtonModel newModel)Sets the model that this button represents.
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);
updateMnemonicProperties();
//We invoke setEnabled() from JComponent
//because setModel() can be called from a constructor
//when the button is not fully initialized
super.setEnabled(newModel.isEnabled());
} else {
mnemonic = '\0";
}
updateDisplayedMnemonicIndex(getText(), mnemonic);
firePropertyChange(MODEL_CHANGED_PROPERTY, oldModel, newModel);
if (newModel != oldModel) {
revalidate();
repaint();
}
|
public void | setMultiClickThreshhold(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.
if (threshhold < 0) {
throw new IllegalArgumentException("threshhold must be >= 0");
}
this.multiClickThreshhold = threshhold;
|
public void | setPressedIcon(javax.swing.Icon pressedIcon)Sets 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 void | setRolloverEnabled(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.
boolean oldValue = rolloverEnabled;
rolloverEnabled = b;
rolloverEnabledSet = true;
firePropertyChange(ROLLOVER_ENABLED_CHANGED_PROPERTY, oldValue, rolloverEnabled);
if (b != oldValue) {
repaint();
}
|
public void | setRolloverIcon(javax.swing.Icon rolloverIcon)Sets 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 void | setRolloverSelectedIcon(javax.swing.Icon rolloverSelectedIcon)Sets 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 void | setSelected(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.
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);
|
private void | setSelectedFromAction(javax.swing.Action a)Sets the seleted state of the button from the action. This is defined
here, but not wired up. Subclasses like JToggleButton and
JCheckBoxMenuItem make use of it.
boolean selected = false;
if (a != null) {
selected = AbstractAction.isSelected(a);
}
if (selected != isSelected()) {
// This won't notify ActionListeners, but that should be
// ok as the change is coming from the Action.
setSelected(selected);
// Make sure the change actually took effect
if (!selected && isSelected()) {
if (getModel() instanceof DefaultButtonModel) {
ButtonGroup group = (ButtonGroup)
((DefaultButtonModel)getModel()).getGroup();
if (group != null) {
group.clearSelection();
}
}
}
}
|
public void | setSelectedIcon(javax.swing.Icon selectedIcon)Sets 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 void | setText(java.lang.String text)Sets 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();
}
|
private void | setTextFromAction(javax.swing.Action a, boolean propertyChange)
boolean hideText = getHideActionText();
if (!propertyChange) {
setText((a != null && !hideText) ?
(String)a.getValue(Action.NAME) : null);
}
else if (!hideText) {
setText((String)a.getValue(Action.NAME));
}
|
public void | setUI(javax.swing.plaf.ButtonUI ui)Sets the L&F object that renders this component.
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);
}
|
void | setUIProperty(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 void | setVerticalAlignment(int alignment)Sets 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 void | setVerticalTextPosition(int textPosition)Sets 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);
revalidate();
repaint();
|
boolean | shouldUpdateSelectedStateFromAction()Button subclasses that support mirroring the selected state from
the action should override this to return true. AbstractButton's
implementation returns false.
return false;
|
void | smallIconChanged(javax.swing.Action a)
if (a.getValue(Action.LARGE_ICON_KEY) == null) {
setIconFromAction(a);
}
|
private void | updateDisplayedMnemonicIndex(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 void | updateMnemonicProperties()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 void | updateUI()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));
|