Java Reference
In-Depth Information
AbstractAction Properties
As Table 2-2 shows, the
AbstractAction
class has three available properties.
Table 2-2.
AbstractAction Properties
Property Name
Data Type
Access
enabled
boolean
Read-write bound
keys
Object [ ]
Read-only
propertyChangeListeners
PropertyChangeListener[ ]
Read-only
The remainder of the bound properties are placed in the lookup table with
putValue
(String key, Object value)
. Getting the current
keys
property setting allows you to find out
which ones can be set en masse, instead of asking for each one individually. Table 2-3 describes
the predefined set of
Action
constants that can be used as the key. You can also add your own
constants, to look up later when the action happens.
Table 2-3.
AbstractAction Lookup Property Keys
Constant
Description
Action
name, used as button label
NAME
Icon for the
Action
, used as button label
SMALL_ICON
Short description of the
Action
; could be used as tooltip text, but
not by default
SHORT_DESCRIPTION
Long description of the
Action
; could be used for accessibility
(see Chapter 22)
LONG_DESCRIPTION
KeyStroke
string; can be used as the accelerator for the
Action
ACCELERATOR
InputMap
key; maps to the
Action
in the
ActionMap
of the associ-
ated
JComponent
ACTION_COMMAND_KEY
MNEMONIC_KEY
Key code; can be used as mnemonic for action
DEFAULT
Unused constant that could be used for your own property
Once a property has been placed in the lookup table, you can get it with
public Object
getValue(String key)
. It works similarly to the
java.util.Hashtable
class or
java.util.Map
interface, with one distinction: if you try to put a key/value pair into the table with a
null
value,
the table removes the key, if it's present.
KeyStroke Class
The
KeyStroke
class and the
inputMap
and
actionMap
properties of a specific
JComponent
provide
a simple replacement for registering
KeyListener
objects to components and watching for