Methods Summary |
---|
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 key is a legal value for the
horizontalAlignment properties.
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)Ensures that the key is a valid. Throws an
IllegalArgumentException
exception otherwise.
if ((key == TOP) || (key == CENTER) || (key == BOTTOM)) {
return key;
} else {
throw new IllegalArgumentException(exception);
}
|
protected void | configurePropertiesFromAction(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
configurePropertiesFromAction(a, null);
|
void | configurePropertiesFromAction(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'
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.ActionListener | createActionListener()
return getHandler();
|
protected java.beans.PropertyChangeListener | createActionPropertyChangeListener(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.
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 int | getHorizontalAlignment()Returns the horizontal alignment of the icon and text.
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();
|
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 | setAction(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 .
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 void | setActionCommand(java.lang.String actionCommand)Sets the action command for this button.
getModel().setActionCommand(actionCommand);
|
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();
}
|
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 | setHorizontalAlignment(int alignment)Sets 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 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);
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();
}
|
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);
|
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);
mnemonic = newModel.getMnemonic();
} 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);
|
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();
}
|
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);
repaint();
|
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));
|