| Method from javax.swing.AbstractButton Detail: |
protected void actionPropertyChanged(Action action,
String propertyName) {
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);
}
}
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. |
public void addActionListener(ActionListener l) {
listenerList.add(ActionListener.class, l);
}
Adds an ActionListener to the button. |
public void addChangeListener(ChangeListener l) {
listenerList.add(ChangeListener.class, l);
}
Adds a ChangeListener to the button. |
protected void addImpl(Component comp,
Object constraints,
int index) {
if (!setLayout) {
setLayout(new OverlayLayout(this));
}
super.addImpl(comp, constraints, index);
}
|
public void addItemListener(ItemListener l) {
listenerList.add(ItemListener.class, l);
}
Adds an ItemListener to the checkbox. |
protected int checkHorizontalKey(int key,
String exception) {
if ((key == LEFT) ||
(key == CENTER) ||
(key == RIGHT) ||
(key == LEADING) ||
(key == TRAILING)) {
return key;
} else {
throw new IllegalArgumentException(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}
|
protected int checkVerticalKey(int key,
String exception) {
if ((key == TOP) || (key == CENTER) || (key == BOTTOM)) {
return key;
} else {
throw new IllegalArgumentException(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}
|
void clientPropertyChanged(Object key,
Object oldValue,
Object newValue) {
if (key == "hideActionText") {
boolean current = (newValue instanceof Boolean) ?
(Boolean)newValue : false;
if (getHideActionText() != current) {
setHideActionText(current);
}
}
}
|
protected void configurePropertiesFromAction(Action a) {
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 ActionListener createActionListener() {
return getHandler();
}
|
protected PropertyChangeListener createActionPropertyChangeListener(Action a) {
return createActionPropertyChangeListener0(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. |
PropertyChangeListener createActionPropertyChangeListener0(Action a) {
return new ButtonActionPropertyChangeListener(this, a);
}
|
protected ChangeListener createChangeListener() {
return getHandler();
}
Subclasses that want to handle ChangeEvents differently
can override this to return another ChangeListener
implementation. |
protected ItemListener createItemListener() {
return getHandler();
}
|
public void doClick() {
doClick(68);
}
Programmatically perform a "click". This does the same
thing as if the user had pressed and released the button. |
public void doClick(int pressTime) {
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);
}
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. |
protected void fireActionPerformed(ActionEvent event) {
// 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);
}
}
}
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the event
parameter. |
protected void fireItemStateChanged(ItemEvent event) {
// 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,
Integer.valueOf(0), Integer.valueOf(1));
} else {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
AccessibleState.SELECTED, null);
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
Integer.valueOf(1), Integer.valueOf(0));
}
}
}
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the event parameter. |
protected void fireStateChanged() {
// 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);
}
}
}
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created. |
public Action getAction() {
return action;
}
Returns the currently set Action for this
ActionEvent source, or null
if no Action is set. |
public String getActionCommand() {
String ac = getModel().getActionCommand();
if(ac == null) {
ac = getText();
}
return ac;
}
Returns the action command for this button. |
public ActionListener[] getActionListeners() {
return (ActionListener[])(listenerList.getListeners(
ActionListener.class));
}
Returns an array of all the ActionListeners added
to this AbstractButton with addActionListener(). |
public ChangeListener[] getChangeListeners() {
return (ChangeListener[])(listenerList.getListeners(
ChangeListener.class));
}
Returns an array of all the ChangeListeners added
to this AbstractButton with addChangeListener(). |
public Icon getDisabledIcon() {
if (disabledIcon == null) {
disabledIcon = UIManager.getLookAndFeel().getDisabledIcon(this, getIcon());
if (disabledIcon != null) {
firePropertyChange(DISABLED_ICON_CHANGED_PROPERTY, null, disabledIcon);
}
}
return disabledIcon;
}
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. |
public Icon getDisabledSelectedIcon() {
if (disabledSelectedIcon == null) {
if (selectedIcon != null) {
disabledSelectedIcon = UIManager.getLookAndFeel().
getDisabledSelectedIcon(this, getSelectedIcon());
} else {
return getDisabledIcon();
}
}
return disabledSelectedIcon;
}
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. |
public int getDisplayedMnemonicIndex() {
return mnemonicIndex;
}
Returns the character, as an index, that the look and feel should
provide decoration for as representing the mnemonic character. |
public boolean getHideActionText() {
return hideActionText;
}
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. |
public int getHorizontalAlignment() {
return horizontalAlignment;
}
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. |
public int getHorizontalTextPosition() {
return horizontalTextPosition;
}
Returns the horizontal position of the text relative to the icon. |
public Icon getIcon() {
return defaultIcon;
}
Returns the default icon. |
public int getIconTextGap() {
return iconTextGap;
}
Returns the amount of space between the text and the icon
displayed in this button. |
public ItemListener[] getItemListeners() {
return (ItemListener[])listenerList.getListeners(ItemListener.class);
}
Returns an array of all the ItemListeners added
to this AbstractButton with addItemListener(). |
public String getLabel() {
return getText();
} Deprecated! - - Replaced by getText
|
public Insets getMargin() {
return (margin == null) ? null : (Insets) margin.clone();
}
Returns the margin between the button's border and
the label. |
public int getMnemonic() {
return mnemonic;
}
Returns the keyboard mnemonic from the the current model. |
public ButtonModel getModel() {
return model;
}
Returns the model that this button represents. |
public long getMultiClickThreshhold() {
return multiClickThreshhold;
}
Gets the amount of time (in milliseconds) required between
mouse press events for the button to generate the corresponding
action events. |
public Icon getPressedIcon() {
return pressedIcon;
}
Returns the pressed icon for the button. |
public Icon getRolloverIcon() {
return rolloverIcon;
}
Returns the rollover icon for the button. |
public Icon getRolloverSelectedIcon() {
return rolloverSelectedIcon;
}
Returns the rollover selection icon for the button. |
public Icon getSelectedIcon() {
return selectedIcon;
}
Returns the selected icon for the button. |
public Object[] getSelectedObjects() {
if (isSelected() == false) {
return null;
}
Object[] selectedObjects = new Object[1];
selectedObjects[0] = getText();
return selectedObjects;
}
Returns an array (length 1) containing the label or
null if the button is not selected. |
public String getText() {
return text;
}
Returns the button's text. |
public ButtonUI getUI() {
return (ButtonUI) ui;
}
Returns the L&F object that renders this component. |
public int getVerticalAlignment() {
return verticalAlignment;
}
Returns the vertical alignment of the text and icon. |
public int getVerticalTextPosition() {
return verticalTextPosition;
}
Returns the vertical position of the text relative to the icon. |
public boolean imageUpdate(Image img,
int infoflags,
int x,
int y,
int w,
int h) {
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);
}
This is overridden to return false if the current Icon's
Image is not equal to the
passed in Image img. |
protected void init(String text,
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() {
return paintBorder;
}
Gets the borderPainted property. |
public boolean isContentAreaFilled() {
return contentAreaFilled;
}
Gets the contentAreaFilled property. |
public boolean isFocusPainted() {
return paintFocus;
}
Gets the paintFocus property. |
public boolean isRolloverEnabled() {
return rolloverEnabled;
}
Gets the rolloverEnabled property. |
public boolean isSelected() {
return model.isSelected();
}
Returns the state of the button. True if the
toggle button is selected, false if it's not. |
void largeIconChanged(Action a) {
setIconFromAction(a);
}
|
protected void paintBorder(Graphics g) {
if (isBorderPainted()) {
super.paintBorder(g);
}
}
Paint the button's border if BorderPainted
property is true and the button has a border. |
protected String paramString() {
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(ActionListener l) {
if ((l != null) && (getAction() == l)) {
setAction(null);
} else {
listenerList.remove(ActionListener.class, 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. |
public void removeChangeListener(ChangeListener l) {
listenerList.remove(ChangeListener.class, l);
}
Removes a ChangeListener from the button. |
public void removeItemListener(ItemListener l) {
listenerList.remove(ItemListener.class, l);
}
Removes an ItemListener from the button. |
public void removeNotify() {
super.removeNotify();
if(isRolloverEnabled()) {
getModel().setRollover(false);
}
}
|
public void setAction(Action a) {
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);
}
}
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. |
public void setActionCommand(String actionCommand) {
getModel().setActionCommand(actionCommand);
}
Sets the action command for this button. |
public void setBorderPainted(boolean b) {
boolean oldValue = paintBorder;
paintBorder = b;
borderPaintedSet = true;
firePropertyChange(BORDER_PAINTED_CHANGED_PROPERTY, oldValue, paintBorder);
if (b != oldValue) {
revalidate();
repaint();
}
}
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. |
public void setContentAreaFilled(boolean b) {
boolean oldValue = contentAreaFilled;
contentAreaFilled = b;
contentAreaFilledSet = true;
firePropertyChange(CONTENT_AREA_FILLED_CHANGED_PROPERTY, oldValue, contentAreaFilled);
if (b != oldValue) {
repaint();
}
}
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. |
public void setDisabledIcon(Icon disabledIcon) {
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();
}
}
}
Sets the disabled icon for the button. |
public void setDisabledSelectedIcon(Icon disabledSelectedIcon) {
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();
}
}
}
Sets the disabled selection icon for the button. |
public void setDisplayedMnemonicIndex(int index) throws IllegalArgumentException {
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();
}
}
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). |
public void setEnabled(boolean b) {
if (!b && model.isRollover()) {
model.setRollover(false);
}
super.setEnabled(b);
model.setEnabled(b);
}
Enables (or disables) the button. |
public void setFocusPainted(boolean b) {
boolean oldValue = paintFocus;
paintFocus = b;
firePropertyChange(FOCUS_PAINTED_CHANGED_PROPERTY, oldValue, paintFocus);
if (b != oldValue && isFocusOwner()) {
revalidate();
repaint();
}
}
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. |
public void setHideActionText(boolean hideActionText) {
if (hideActionText != this.hideActionText) {
this.hideActionText = hideActionText;
if (getAction() != null) {
setTextFromAction(getAction(), false);
}
firePropertyChange("hideActionText", !hideActionText,
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. |
public void setHorizontalAlignment(int alignment) {
if (alignment == horizontalAlignment) return;
int oldValue = horizontalAlignment;
horizontalAlignment = checkHorizontalKey(alignment,
"horizontalAlignment");
firePropertyChange(HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY,
oldValue, horizontalAlignment);
repaint();
}
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. |
public void setHorizontalTextPosition(int textPosition) {
if (textPosition == horizontalTextPosition) return;
int oldValue = horizontalTextPosition;
horizontalTextPosition = checkHorizontalKey(textPosition,
"horizontalTextPosition");
firePropertyChange(HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY,
oldValue,
horizontalTextPosition);
revalidate();
repaint();
}
Sets the horizontal position of the text relative to the icon. |
public void setIcon(Icon defaultIcon) {
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();
}
}
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. |
void setIconFromAction(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) {
int oldValue = this.iconTextGap;
this.iconTextGap = iconTextGap;
iconTextGapSet = true;
firePropertyChange("iconTextGap", oldValue, iconTextGap);
if (iconTextGap != oldValue) {
revalidate();
repaint();
}
}
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. |
public void setLabel(String label) {
setText(label);
} Deprecated! - - Replaced by setText(text)
|
public void setLayout(LayoutManager mgr) {
setLayout = true;
super.setLayout(mgr);
}
|
public void setMargin(Insets m) {
// 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();
}
}
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). |
public void setMnemonic(int mnemonic) {
int oldValue = getMnemonic();
model.setMnemonic(mnemonic);
updateMnemonicProperties();
}
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. |
public void setMnemonic(char mnemonic) {
int vk = (int) mnemonic;
if(vk >= 'a" && vk < ='z")
vk -= ('a" - 'A");
setMnemonic(vk);
}
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'. |
public void setModel(ButtonModel newModel) {
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();
}
}
Sets the model that this button represents. |
public void setMultiClickThreshhold(long threshhold) {
if (threshhold < 0) {
throw new IllegalArgumentException("threshhold must be >= 0");
}
this.multiClickThreshhold = 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. |
public void setPressedIcon(Icon pressedIcon) {
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();
}
}
}
Sets the pressed icon for the button. |
public void setRolloverEnabled(boolean b) {
boolean oldValue = rolloverEnabled;
rolloverEnabled = b;
rolloverEnabledSet = true;
firePropertyChange(ROLLOVER_ENABLED_CHANGED_PROPERTY, oldValue, rolloverEnabled);
if (b != oldValue) {
repaint();
}
}
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. |
public void setRolloverIcon(Icon rolloverIcon) {
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();
}
}
Sets the rollover icon for the button. |
public void setRolloverSelectedIcon(Icon rolloverSelectedIcon) {
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();
}
}
}
Sets the rollover selected icon for the button. |
public void setSelected(boolean b) {
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);
}
Sets the state of the button. Note that this method does not
trigger an actionEvent.
Call doClick to perform a programatic action change. |
public void setSelectedIcon(Icon selectedIcon) {
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();
}
}
}
Sets the selected icon for the button. |
public void setText(String 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 void setUI(ButtonUI ui) {
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);
}
}
Sets the L&F object that renders this component. |
void setUIProperty(String propertyName,
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) {
if (alignment == verticalAlignment) return;
int oldValue = verticalAlignment;
verticalAlignment = checkVerticalKey(alignment, "verticalAlignment");
firePropertyChange(VERTICAL_ALIGNMENT_CHANGED_PROPERTY, oldValue, verticalAlignment); repaint();
}
Sets the vertical alignment of the icon and text. |
public void setVerticalTextPosition(int textPosition) {
if (textPosition == verticalTextPosition) return;
int oldValue = verticalTextPosition;
verticalTextPosition = checkVerticalKey(textPosition, "verticalTextPosition");
firePropertyChange(VERTICAL_TEXT_POSITION_CHANGED_PROPERTY, oldValue, verticalTextPosition);
revalidate();
repaint();
}
Sets the vertical position of the text relative to the icon. |
boolean shouldUpdateSelectedStateFromAction() {
return false;
}
Button subclasses that support mirroring the selected state from
the action should override this to return true. AbstractButton's
implementation returns false. |
void smallIconChanged(Action a) {
if (a.getValue(Action.LARGE_ICON_KEY) == null) {
setIconFromAction(a);
}
}
|
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));
|