This method is now obsolete, please use a combination of
getActionMap()
and
getInputMap()
for
similiar behavior. For example, to bind the
KeyStroke
aKeyStroke
to the
Action
anAction
now use:
component.getInputMap().put(aKeyStroke, aCommand);
component.getActionMap().put(aCommmand, anAction);
The above assumes you want the binding to be applicable for
WHEN_FOCUSED
. To register bindings for other focus
states use the
getInputMap
method that takes an integer.
Register a new keyboard action.
anAction
will be invoked if a key event matching
aKeyStroke
occurs and aCondition
is verified.
The KeyStroke
object defines a
particular combination of a keyboard key and one or more modifiers
(alt, shift, ctrl, meta).
The aCommand
will be set in the delivered event if
specified.
The aCondition
can be one of:
- WHEN_FOCUSED
- The action will be invoked only when the keystroke occurs
while the component has the focus.
- WHEN_IN_FOCUSED_WINDOW
- The action will be invoked when the keystroke occurs while
the component has the focus or if the component is in the
window that has the focus. Note that the component need not
be an immediate descendent of the window -- it can be
anywhere in the window's containment hierarchy. In other
words, whenever any component in the window has the focus,
the action registered with this component is invoked.
- WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
- The action will be invoked when the keystroke occurs while the
component has the focus or if the component is an ancestor of
the component that has the focus.
The combination of keystrokes and conditions lets you define high
level (semantic) action events for a specified keystroke+modifier
combination (using the KeyStroke class) and direct to a parent or
child of a component that has the focus, or to the component itself.
In other words, in any hierarchical structure of components, an
arbitrary key-combination can be immediately directed to the
appropriate component in the hierarchy, and cause a specific method
to be invoked (usually by way of adapter objects).
If an action has already been registered for the receiving
container, with the same charCode and the same modifiers,
anAction
will replace the action.
Parameters:
- anAction - the Action
to be registered
- aCommand - the command to be set in the delivered event
- aKeyStroke - the KeyStroke
to bind to the action
- aCondition - the condition that needs to be met, see above
See Also:
KeyStroke
,