java.lang.Object
javax.swing.InputMap
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ComponentInputMap
,InputMapUIResource
InputMap
provides a binding between an input event (currently only
KeyStroke
s are used) and an Object
. InputMap
s are
usually used with an ActionMap
, to determine an Action
to
perform when a key is pressed. An InputMap
can have a parent that
is searched for bindings not defined in the InputMap
.
As with ActionMap
if you create a cycle, eg:
InputMap am = new InputMap(); InputMap bm = new InputMap(): am.setParent(bm); bm.setParent(am);some of the methods will cause a StackOverflowError to be thrown.
- Since:
- 1.3
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionallKeys()
Returns an array of theKeyStroke
s defined in thisInputMap
and its parent.void
clear()
Removes all the mappings from thisInputMap
.Returns the binding forkeyStroke
, messaging the parentInputMap
if the binding is not locally defined.Gets thisInputMap
's parent.keys()
Returns theKeyStroke
s that are bound in thisInputMap
.void
Adds a binding forkeyStroke
toactionMapKey
.void
Removes the binding forkey
from thisInputMap
.void
Sets thisInputMap
's parent.int
size()
Returns the number ofKeyStroke
bindings.
-
Constructor Details
-
InputMap
public InputMap()Creates anInputMap
with no parent and no mappings.
-
-
Method Details
-
setParent
Sets thisInputMap
's parent.- Parameters:
map
- theInputMap
that is the parent of this one
-
getParent
Gets thisInputMap
's parent.- Returns:
- map the
InputMap
that is the parent of this one, or null if thisInputMap
has no parent
-
put
Adds a binding forkeyStroke
toactionMapKey
. IfactionMapKey
is null, this removes the current binding forkeyStroke
.- Parameters:
keyStroke
- aKeyStroke
actionMapKey
- an action map key
-
get
Returns the binding forkeyStroke
, messaging the parentInputMap
if the binding is not locally defined.- Parameters:
keyStroke
- theKeyStroke
for which to get the binding- Returns:
- the binding for
keyStroke
-
remove
Removes the binding forkey
from thisInputMap
.- Parameters:
key
- theKeyStroke
for which to remove the binding
-
clear
public void clear()Removes all the mappings from thisInputMap
. -
keys
Returns theKeyStroke
s that are bound in thisInputMap
.- Returns:
- an array of the
KeyStroke
s that are bound in thisInputMap
-
size
public int size()Returns the number ofKeyStroke
bindings.- Returns:
- the number of
KeyStroke
bindings
-
allKeys
Returns an array of theKeyStroke
s defined in thisInputMap
and its parent. This differs fromkeys()
in that this method includes the keys defined in the parent.- Returns:
- an array of the
KeyStroke
s defined in thisInputMap
and its parent
-