|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.AbstractButton
public abstract class AbstractButton
Provides an abstract implementation of common button behaviour, data model and look & feel.
This class is supposed to serve as a base class for several kinds of buttons with similar but non-identical semantics: toggle buttons (radio buttons and checkboxes), simple push buttons, menu items, etc.
Buttons have many properties, some of which are stored in this class while others are delegated to the button's model. The following properties are available:
Property | Stored in | Bound? |
---|---|---|
action | button | no |
actionCommand | model | no |
borderPainted | button | yes |
contentAreaFilled | button | yes |
disabledIcon | button | yes |
disabledSelectedIcon | button | yes |
displayedMnemonicIndex | button | no |
enabled | model | no |
focusPainted | button | yes |
horizontalAlignment | button | yes |
horizontalTextPosition | button | yes |
icon | button | yes |
iconTextGap | button | no |
label (same as text) | model | yes |
margin | button | yes |
multiClickThreshold | button | no |
pressedIcon | button | yes |
rolloverEnabled | button | yes |
rolloverIcon | button | yes |
rolloverSelectedIcon | button | yes |
selected | model | no |
selectedIcon | button | yes |
selectedObjects | button | no |
text | model | yes |
UI | button | yes |
verticalAlignment | button | yes |
verticalTextPosition | button | yes |
The various behavioral aspects of these properties follows:
true
, the model will fire an ActionEvent to its
ActionListeners, which include the button. The button will propagate
this ActionEvent to its ActionListeners, with the ActionEvent's "source"
property set to refer to the button, rather than the model.
Nested Class Summary | |
---|---|
protected class |
AbstractButton.AccessibleAbstractButton
A Java Accessibility extension of the AbstractButton. |
protected class |
AbstractButton.ButtonChangeListener
An extension of ChangeListener to be serializable. |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
protected ActionListener |
actionListener
Listener the button uses to receive ActionEvents from its model. |
static String |
BORDER_PAINTED_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "borderPainted" property changes. |
protected ChangeEvent |
changeEvent
ChangeEvent that is fired to button's ChangeEventListeners |
protected ChangeListener |
changeListener
Listener the button uses to receive ChangeEvents from its model. |
static String |
CONTENT_AREA_FILLED_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "contentAreaFilled" property changes. |
static String |
DISABLED_ICON_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "disabledIcon" property changes. |
static String |
DISABLED_SELECTED_ICON_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "disabledSelectedIcon" property changes. |
static String |
FOCUS_PAINTED_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "focusPainted" property changes. |
static String |
HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "horizontalAlignment" property changes. |
static String |
HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "horizontalTextPosition" property changes. |
static String |
ICON_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "icon" property changes. |
protected ItemListener |
itemListener
Listener the button uses to receive ItemEvents from its model. |
static String |
MARGIN_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "margin" property changes. |
static String |
MNEMONIC_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "mnemonic" property changes. |
protected ButtonModel |
model
The button's current state. |
static String |
MODEL_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "model" property changes. |
static String |
PRESSED_ICON_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "pressedIcon" property changes. |
static String |
ROLLOVER_ENABLED_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "rolloverEnabled" property changes. |
static String |
ROLLOVER_ICON_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "rolloverIcon" property changes. |
static String |
ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "rolloverSelectedIcon" property changes. |
static String |
SELECTED_ICON_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "selectedIcon" property changes. |
static String |
TEXT_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "text" property changes. |
static String |
VERTICAL_ALIGNMENT_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "verticalAlignment" property changes. |
static String |
VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
Fired in a PropertyChangeEvent when the "verticalTextPosition" property changes. |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface javax.swing.SwingConstants |
---|
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
AbstractButton()
Creates a new AbstractButton object. |
Method Summary | |
---|---|
void |
addActionListener(ActionListener l)
Adds an ActionListener to the button's listener list. |
void |
addChangeListener(ChangeListener l)
Adds a ChangeListener to the button's listener list. |
protected void |
addImpl(Component comp,
Object constraints,
int index)
Adds the specified component to this AbstractButton. |
void |
addItemListener(ItemListener l)
Adds an ItemListener to the button's listener list. |
protected int |
checkHorizontalKey(int key,
String exception)
Verifies that a particular key is one of the valid constants used for describing horizontal alignment and positioning. |
protected int |
checkVerticalKey(int key,
String exception)
Verifies that a particular key is one of the valid constants used for describing vertical alignment and positioning. |
protected void |
configurePropertiesFromAction(Action a)
Configure various properties of the button by reading properties of an Action . |
protected ActionListener |
createActionListener()
A factory method which should return an ActionListener that
propagates events from the button's ButtonModel to any of the
button's ActionListeners. |
protected PropertyChangeListener |
createActionPropertyChangeListener(Action a)
A factory method which should return a PropertyChangeListener
that accepts changes to the specified Action and reconfigure
the AbstractButton , by default using the configurePropertiesFromAction(javax.swing.Action) method. |
protected ChangeListener |
createChangeListener()
Factory method which creates a AbstractButton.ButtonChangeListener , used to
subscribe to ChangeEvents from the button's model. |
protected ItemListener |
createItemListener()
Factory method which creates a ItemListener , used to
subscribe to ItemEvents from the button's model. |
void |
doClick()
Programmatically perform a "click" on the button: arming, pressing, waiting, un-pressing, and disarming the model. |
void |
doClick(int pressTime)
Programmatically perform a "click" on the button: arming, pressing, waiting, un-pressing, and disarming the model. |
protected void |
fireActionPerformed(ActionEvent e)
Calls ActionListener.actionPerformed(java.awt.event.ActionEvent) on each ActionListener in the button's listener list. |
protected void |
fireItemStateChanged(ItemEvent e)
Calls ItemListener.itemStateChanged(java.awt.event.ItemEvent) on each ItemListener in
the button's listener list. |
protected void |
fireStateChanged()
Calls AbstractButton.ButtonChangeListener.stateChanged(javax.swing.event.ChangeEvent) on each AbstractButton.ButtonChangeListener
in the button's listener list. |
Action |
getAction()
Get the value of the "action" property. |
String |
getActionCommand()
Returns the action command string for this button's model. |
ActionListener[] |
getActionListeners()
Returns all added ActionListener objects. |
ChangeListener[] |
getChangeListeners()
Returns all added ChangeListener objects. |
Icon |
getDisabledIcon()
Return the button's "disabledIcon" property. |
Icon |
getDisabledSelectedIcon()
Return the button's disabled selected icon. |
int |
getDisplayedMnemonicIndex()
Get the button's mnemonic index, which is an offset into the button's "text" property. |
int |
getHorizontalAlignment()
Set the horizontal alignment of the button's text and icon. |
int |
getHorizontalTextPosition()
Get the horizontal position of the button's text relative to its icon. |
Icon |
getIcon()
Return the button's default "icon" property. |
int |
getIconTextGap()
Get the value of the iconTextGap property. |
ItemListener[] |
getItemListeners()
Returns all added ItemListener objects. |
String |
getLabel()
Deprecated. use getText() |
Insets |
getMargin()
Return the button's "margin" property, which is an Insets object
describing the distance between the button's border and its text and
icon. |
int |
getMnemonic()
Get the current keyboard mnemonic value. |
ButtonModel |
getModel()
Get the model the button is currently using. |
long |
getMultiClickThreshhold()
Returns the current time in milliseconds in which clicks gets coalesced into a single ActionEvent . |
Icon |
getPressedIcon()
Return the button's "pressedIcon" property. |
Icon |
getRolloverIcon()
Return the button's rollover icon. |
Icon |
getRolloverSelectedIcon()
Return the button's rollover selected icon. |
Icon |
getSelectedIcon()
Return the button's selected icon. |
Object[] |
getSelectedObjects()
Returns an single-element array containing the "text" property of the button if the "selected" property of the button's model is true , otherwise returns null . |
String |
getText()
Return the button's "text" property. |
ButtonUI |
getUI()
Set the "UI" property of the button, which is a look and feel class responsible for handling the button's input events and painting it. |
int |
getVerticalAlignment()
Get the vertical alignment of the button's text and icon. |
int |
getVerticalTextPosition()
Get the vertical position of the button's text relative to its icon. |
boolean |
imageUpdate(Image img,
int infoflags,
int x,
int y,
int w,
int h)
Called when image data becomes available for one of the button's icons. |
protected void |
init(String text,
Icon icon)
|
boolean |
isBorderPainted()
Set the value of the "borderPainted" property. |
boolean |
isContentAreaFilled()
Returns the value of the button's "contentAreaFilled" property. |
boolean |
isFocusPainted()
Return the button's "paintFocus" property. |
boolean |
isRolloverEnabled()
Returns whether or not rollover icon changes are enabled on the button. |
boolean |
isSelected()
Get the value of the button's "selected" property. |
protected void |
paintBorder(Graphics g)
Paints the button's border, if the button's "borderPainted" property is true , by out calling to the button's look and feel class. |
protected String |
paramString()
Returns a string, used only for debugging, which identifies or somehow represents this button. |
void |
removeActionListener(ActionListener l)
Removes an ActionListener from the button's listener list. |
void |
removeChangeListener(ChangeListener l)
Removes a ChangeListener from the button's listener list. |
void |
removeItemListener(ItemListener l)
Removes an ItemListener from the button's listener list. |
void |
setAction(Action a)
Set the button's "action" property, subscribing the new action to the button, as an ActionListener, if it is not already subscribed. |
void |
setActionCommand(String actionCommand)
Sets the action command string for this button's model. |
void |
setBorderPainted(boolean b)
Set the value of the "borderPainted" property. |
void |
setContentAreaFilled(boolean b)
Sets the value of the button's "contentAreaFilled" property. |
void |
setDisabledIcon(Icon d)
Set the button's "disabledIcon" property. |
void |
setDisabledSelectedIcon(Icon icon)
Set the button's disabled selected icon. |
void |
setDisplayedMnemonicIndex(int index)
Sets the button's mnemonic index. |
void |
setEnabled(boolean b)
Enables or disables the button. |
void |
setFocusPainted(boolean p)
Set the button's "paintFocus" property. |
void |
setHorizontalAlignment(int a)
Set the horizontal alignment of the button's text and icon. |
void |
setHorizontalTextPosition(int t)
Set the horizontal position of the button's text relative to its icon. |
void |
setIcon(Icon i)
Set the button's default "icon" property. |
void |
setIconTextGap(int i)
Set the value of the iconTextGap property. |
void |
setLabel(String label)
Deprecated. use setText(text) |
void |
setLayout(LayoutManager layout)
Sets a layout manager on this AbstractButton. |
void |
setMargin(Insets m)
Set the button's "margin" property, which is an Insets object
describing the distance between the button's border and its text and
icon. |
void |
setMnemonic(char mne)
Set the current keyboard mnemonic value. |
void |
setMnemonic(int mne)
Set the current keyboard mnemonic value. |
void |
setModel(ButtonModel newModel)
Set the model the button is currently using. |
void |
setMultiClickThreshhold(long threshhold)
Sets the time in milliseconds in which clicks gets coalesced into a single ActionEvent . |
void |
setPressedIcon(Icon pressedIcon)
Set the button's "pressedIcon" property. |
void |
setRolloverEnabled(boolean r)
Set the "rolloverEnabled" property. |
void |
setRolloverIcon(Icon r)
Set the button's rollover icon and sets the rolloverEnabled
property to true . |
void |
setRolloverSelectedIcon(Icon r)
Set the button's rollover selected icon and sets the rolloverEnabled property to true . |
void |
setSelected(boolean s)
Set the value of the button's "selected" property. |
void |
setSelectedIcon(Icon s)
Set the button's selected icon. |
void |
setText(String t)
Set the button's "text" property. |
void |
setUI(ButtonUI ui)
Set the "UI" property of the button, which is a look and feel class responsible for handling the button's input events and painting it. |
void |
setVerticalAlignment(int a)
Set the vertical alignment of the button's text and icon. |
void |
setVerticalTextPosition(int t)
Set the vertical position of the button's text relative to its icon. |
void |
updateUI()
Set the "UI" property to a class constructed, via the UIManager , from the current look and feel. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected ButtonModel model
protected ActionListener actionListener
protected ItemListener itemListener
protected ChangeListener changeListener
protected ChangeEvent changeEvent
public static final String BORDER_PAINTED_CHANGED_PROPERTY
public static final String CONTENT_AREA_FILLED_CHANGED_PROPERTY
public static final String DISABLED_ICON_CHANGED_PROPERTY
public static final String DISABLED_SELECTED_ICON_CHANGED_PROPERTY
public static final String FOCUS_PAINTED_CHANGED_PROPERTY
public static final String HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY
public static final String HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY
public static final String ICON_CHANGED_PROPERTY
public static final String MARGIN_CHANGED_PROPERTY
public static final String MNEMONIC_CHANGED_PROPERTY
public static final String MODEL_CHANGED_PROPERTY
public static final String PRESSED_ICON_CHANGED_PROPERTY
public static final String ROLLOVER_ENABLED_CHANGED_PROPERTY
public static final String ROLLOVER_ICON_CHANGED_PROPERTY
public static final String ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY
public static final String SELECTED_ICON_CHANGED_PROPERTY
public static final String TEXT_CHANGED_PROPERTY
public static final String VERTICAL_ALIGNMENT_CHANGED_PROPERTY
public static final String VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
Constructor Detail |
---|
public AbstractButton()
super(); init(text, icon);The
init(String, Icon)
method is not called automatically by this
constructor.
init(String, Icon)
Method Detail |
---|
public ButtonModel getModel()
public void setModel(ButtonModel newModel)
newModel
- The new modelprotected void init(String text, Icon icon)
public String getActionCommand()
Returns the action command string for this button's model.
If the action command was set to null
, the button's
text (label) is returned instead.
public void setActionCommand(String actionCommand)
actionCommand
- The new action command string to set in the button's
model.public void addActionListener(ActionListener l)
l
- The new listener to addpublic void removeActionListener(ActionListener l)
l
- The listener to removepublic ActionListener[] getActionListeners()
ActionListener
objects.
public void addItemListener(ItemListener l)
addItemListener
in interface ItemSelectable
l
- The new listener to addpublic void removeItemListener(ItemListener l)
removeItemListener
in interface ItemSelectable
l
- The listener to removepublic ItemListener[] getItemListeners()
ItemListener
objects.
public void addChangeListener(ChangeListener l)
l
- The new listener to addpublic void removeChangeListener(ChangeListener l)
l
- The listener to removepublic ChangeListener[] getChangeListeners()
ChangeListener
objects.
protected void fireItemStateChanged(ItemEvent e)
ItemListener.itemStateChanged(java.awt.event.ItemEvent)
on each ItemListener in
the button's listener list.
e
- The event signifying that the button's model changed stateprotected void fireActionPerformed(ActionEvent e)
ActionListener.actionPerformed(java.awt.event.ActionEvent)
on each ActionListener
in the button's listener list.
e
- The event signifying that the button's model was clickedprotected void fireStateChanged()
AbstractButton.ButtonChangeListener.stateChanged(javax.swing.event.ChangeEvent)
on each AbstractButton.ButtonChangeListener
in the button's listener list.
public int getMnemonic()
KeyEvent
VK_*
codes) and is used to activate the button when pressed in conjunction
with the "mouseless modifier" of the button's look and feel class, and
when focus is in one of the button's ancestors.
public void setMnemonic(char mne)
KeyEvent
VK_*
codes) and is used to activate the button when pressed in conjunction
with the "mouseless modifier" of the button's look and feel class, and
when focus is in one of the button's ancestors.
mne
- A new mnemonic to use for the buttonpublic void setMnemonic(int mne)
KeyEvent
VK_*
codes) and is used to activate the button when pressed in conjunction
with the "mouseless modifier" of the button's look and feel class, and
when focus is in one of the button's ancestors.
mne
- A new mnemonic to use for the buttonpublic void setDisplayedMnemonicIndex(int index)
index
- An offset into the "text" property of the button
IllegalArgumentException
- If index
is not within the
range of legal offsets for the "text" property of the button.public int getDisplayedMnemonicIndex()
public void setRolloverEnabled(boolean r)
r
- Whether or not to enable rollover icon changespublic boolean isRolloverEnabled()
public void setSelected(boolean s)
s
- New value for the propertypublic boolean isSelected()
public void setEnabled(boolean b)
setEnabled
in class JComponent
b
- Whether or not to enable the buttonComponent.isEnabled()
,
Component.isLightweight()
public int getHorizontalAlignment()
SwingConstants
. It must
be one of: RIGHT
, LEFT
, CENTER
,
LEADING
or TRAILING
. The default is
CENTER
.
setHorizontalAlignment(int)
public void setHorizontalAlignment(int a)
SwingConstants
. It must
be one of: RIGHT
, LEFT
, CENTER
,
LEADING
or TRAILING
. The default is
CENTER
.
a
- The new horizontal alignment
IllegalArgumentException
- If alignment is not one of the legal
constants.getHorizontalAlignment()
public int getHorizontalTextPosition()
SwingConstants
. It must be one of: RIGHT
,
LEFT
, CENTER
, LEADING
or
TRAILING
. The default is TRAILING
.
public void setHorizontalTextPosition(int t)
SwingConstants
. It must be one of: RIGHT
,
LEFT
, CENTER
, LEADING
or
TRAILING
. The default is TRAILING
.
t
- The new horizontal text position
IllegalArgumentException
- If position is not one of the legal
constants.public int getVerticalAlignment()
SwingConstants
. It must
be one of: CENTER
, TOP
, or
BOTTOM
. The default is CENTER
.
setVerticalAlignment(int)
public void setVerticalAlignment(int a)
SwingConstants
. It must
be one of: CENTER
, TOP
, or
BOTTOM
. The default is CENTER
.
a
- The new vertical alignment
IllegalArgumentException
- If alignment is not one of the legal
constants.getVerticalAlignment()
public int getVerticalTextPosition()
SwingConstants
. It must be one of: CENTER
,
TOP
, or BOTTOM
. The default is
CENTER
.
public void setVerticalTextPosition(int t)
SwingConstants
. It must be one of: CENTER
,
TOP
, or BOTTOM
. The default is
CENTER
.
t
- The new vertical position
IllegalArgumentException
- If position is not one of the legal
constants.public boolean isBorderPainted()
false
, the button's look and feel class should not paint
a border for the button. The default is true
.
public void setBorderPainted(boolean b)
false
, the button's look and feel class should not paint
a border for the button. The default is true
.
b
- The new value of the property.public Action getAction()
public void setAction(Action a)
Set the button's "action" property, subscribing the new action to the button, as an ActionListener, if it is not already subscribed. The old Action, if it exists, is unsubscribed, and the button is unsubscribed from the old Action if it was previously subscribed as a PropertyChangeListener.
This method also configures several of the button's properties from
the Action, by calling configurePropertiesFromAction(javax.swing.Action)
, and
subscribes the button to the Action as a PropertyChangeListener.
Subsequent changes to the Action will thus reconfigure the button
automatically.
a
- The new value of the "action" propertypublic Icon getIcon()
public void setIcon(Icon i)
i
- The new default iconpublic String getText()
public void setLabel(String label)
setText(text)
label
- The new "label" propertypublic String getLabel()
getText()
public void setText(String t)
t
- The new "text" propertypublic void setIconTextGap(int i)
iconTextGap
property.
i
- The new value of the propertypublic int getIconTextGap()
iconTextGap
property.
public Insets getMargin()
Insets
object
describing the distance between the button's border and its text and
icon.
public void setMargin(Insets m)
Insets
object
describing the distance between the button's border and its text and
icon.
m
- The new "margin" propertypublic Icon getPressedIcon()
ButtonModel
is true
. This property may be
null
, in which case the default icon is used.
public void setPressedIcon(Icon pressedIcon)
ButtonModel
is true
. This property may be
null
, in which case the default icon is used.
pressedIcon
- The new "pressedIcon" propertypublic Icon getDisabledIcon()
ButtonModel
is false
. This property may be
null
, in which case an icon is constructed, based on the
default icon.
public void setDisabledIcon(Icon d)
ButtonModel
is false
. This property may be
null
, in which case an icon is constructed, based on the
default icon.
d
- The new "disabledIcon" propertypublic boolean isFocusPainted()
public void setFocusPainted(boolean p)
p
- The new "paintFocus" propertyprotected int checkHorizontalKey(int key, String exception)
SwingConstants
:
RIGHT
, LEFT
, CENTER
,
LEADING
or TRAILING
.
key
- The key to checkexception
- A message to include in an IllegalArgumentException
IllegalArgumentException
- If key is not one of the valid constantssetHorizontalTextPosition(int)
,
setHorizontalAlignment(int)
protected int checkVerticalKey(int key, String exception)
SwingConstants
: TOP
,
BOTTOM
or CENTER
.
key
- The key to checkexception
- A message to include in an IllegalArgumentException
IllegalArgumentException
- If key is not one of the valid constantssetVerticalTextPosition(int)
,
setVerticalAlignment(int)
protected void configurePropertiesFromAction(Action a)
Action
. The mapping of properties is as follows:
Action keyed property | AbstractButton property |
---|---|
NAME | text |
SMALL_ICON | icon |
SHORT_DESCRIPTION | toolTipText |
MNEMONIC_KEY | mnemonic |
ACTION_COMMAND_KEY | actionCommand |
In addition, this method always sets the button's "enabled" property to the value of the Action's "enabled" property.
If the provided Action is null
, the text, icon, and
toolTipText properties of the button are set to null
, and
the "enabled" property is set to true
; the mnemonic and
actionCommand properties are unchanged.
a
- An Action to configure the button fromprotected ActionListener createActionListener()
A factory method which should return an ActionListener
that
propagates events from the button's ButtonModel
to any of the
button's ActionListeners. By default, this is an inner class which
calls fireActionPerformed(java.awt.event.ActionEvent)
with a modified copy
of the incoming model ActionEvent
.
The button calls this method during construction, stores the
resulting ActionListener in its actionListener
member
field, and subscribes it to the button's model. If the button's model
is changed, this listener is unsubscribed from the old model and
subscribed to the new one.
protected PropertyChangeListener createActionPropertyChangeListener(Action a)
A factory method which should return a PropertyChangeListener
that accepts changes to the specified Action
and reconfigure
the AbstractButton
, by default using the configurePropertiesFromAction(javax.swing.Action)
method.
The button calls this method whenever a new Action is assigned to
the button's "action" property, via setAction(javax.swing.Action)
, and stores the
resulting PropertyChangeListener in its
actionPropertyChangeListener
member field. The button
then subscribes the listener to the button's new action. If the
button's action is changed subsequently, the listener is unsubscribed
from the old action and subscribed to the new one.
a
- The Action which will be listened to, and which should be
the same as the source of any PropertyChangeEvents received by the
new listener returned from this method.
protected ChangeListener createChangeListener()
Factory method which creates a AbstractButton.ButtonChangeListener
, used to
subscribe to ChangeEvents from the button's model. Subclasses of
AbstractButton may wish to override the listener used to subscribe to
such ChangeEvents. By default, the listener just propagates the
ChangeEvent
to the button's ChangeListeners, via the fireStateChanged()
method.
The button calls this method during construction, stores the
resulting ChangeListener in its changeListener
member
field, and subscribes it to the button's model. If the button's model
is changed, this listener is unsubscribed from the old model and
subscribed to the new one.
protected ItemListener createItemListener()
Factory method which creates a ItemListener
, used to
subscribe to ItemEvents from the button's model. Subclasses of
AbstractButton may wish to override the listener used to subscribe to
such ItemEvents. By default, the listener just propagates the
ItemEvent
to the button's ItemListeners, via the fireItemStateChanged(java.awt.event.ItemEvent)
method.
The button calls this method during construction, stores the
resulting ItemListener in its changeListener
member
field, and subscribes it to the button's model. If the button's model
is changed, this listener is unsubscribed from the old model and
subscribed to the new one.
Note that ItemEvents are only generated from the button's model when the model's selected property changes. If you want to subscribe to other properties of the model, you must subscribe to ChangeEvents.
public void doClick()
public void doClick(int pressTime)
pressTime
- The number of milliseconds to wait in the pressed statepublic Icon getDisabledSelectedIcon()
false
and its "selected" property is
true
. This icon can be null
, in which case
it is synthesized from the button's selected icon.
public void setDisabledSelectedIcon(Icon icon)
false
and its "selected" property is
true
. This icon can be null
, in which case
it is synthesized from the button's selected icon.
icon
- The new disabled selected iconpublic Icon getRolloverIcon()
true
and the mouse rolls over the button.
public void setRolloverIcon(Icon r)
rolloverEnabled
property to true
. The look and feel class should
paint this icon when the "rolloverEnabled" property of the button is
true
and the mouse rolls over the button.
r
- The new rollover iconpublic Icon getRolloverSelectedIcon()
true
, the "selected" property of the button's model is
true
, and the mouse rolls over the button.
public void setRolloverSelectedIcon(Icon r)
rolloverEnabled
property to true
. The look and
feel class should paint this icon when the "rolloverEnabled" property of
the button is true
, the "selected" property of the button's
model is true
, and the mouse rolls over the button.
r
- The new rollover selected icon.public Icon getSelectedIcon()
true
, and either the "rolloverEnabled" property of the
button is false
or the mouse is not currently rolled
over the button.
public void setSelectedIcon(Icon s)
true
, and either the "rolloverEnabled" property of the
button is false
or the mouse is not currently rolled
over the button.
s
- The new selected iconpublic Object[] getSelectedObjects()
true
, otherwise returns null
.
getSelectedObjects
in interface ItemSelectable
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
imageUpdate
in interface ImageObserver
imageUpdate
in class Component
img
- The image being updatedinfoflags
- One of the constant codes in ImageObserver
used
to describe updated portions of an image.x
- X coordinate of the region being updatedy
- Y coordinate of the region being updatedw
- Width of the region beign updatedh
- Height of the region being updated
true
if img is equal to the button's current icon,
otherwise false
ImageObserver
,
Graphics.drawImage(Image, int, int, Color, ImageObserver)
,
Graphics.drawImage(Image, int, int, ImageObserver)
,
Graphics.drawImage(Image, int, int, int, int, Color, ImageObserver)
,
Graphics.drawImage(Image, int, int, int, int, ImageObserver)
,
ImageObserver.imageUpdate(Image, int, int, int, int, int)
public boolean isContentAreaFilled()
false
, the look and feel class should leave
the content area transparent.
public void setContentAreaFilled(boolean b)
false
, the look and feel class should leave
the content area transparent.
b
- The new value of the "contentAreaFilled" propertyprotected void paintBorder(Graphics g)
true
, by out calling to the button's look and feel class.
paintBorder
in class JComponent
g
- The graphics context used to paint the borderJComponent.paint(java.awt.Graphics)
,
JComponent.paintChildren(java.awt.Graphics)
,
JComponent.paintComponent(java.awt.Graphics)
protected String paramString()
paramString
in class JComponent
public void setUI(ButtonUI ui)
ui
- The new "UI" propertypublic ButtonUI getUI()
public void updateUI()
UIManager
, from the current look and feel. This should be overridden
for each subclass of AbstractButton, to retrieve a suitable ButtonUI
look and feel class.
updateUI
in class JComponent
public long getMultiClickThreshhold()
ActionEvent
.
public void setMultiClickThreshhold(long threshhold)
ActionEvent
.
threshhold
- the time in millisecondsprotected void addImpl(Component comp, Object constraints, int index)
OverlayLayout
layout manager
before adding the component. The layout manager is only installed if
no other layout manager has been installed before.
addImpl
in class Container
comp
- the component to be addedconstraints
- constraints for the layout managerindex
- the index at which the component is addedpublic void setLayout(LayoutManager layout)
addImpl(Component, Object, int)
installs
an OverlayLayout before adding a component.
setLayout
in class Container
layout
- the layout manager to install
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |