InputMap (Java SE 19 & JDK 19) (original) (raw)
All Implemented Interfaces:
[Serializable](../../../java.base/java/io/Serializable.html "interface in java.io")
Direct Known Subclasses:
[ComponentInputMap](ComponentInputMap.html "class in javax.swing")
, [InputMapUIResource](plaf/InputMapUIResource.html "class in javax.swing.plaf")
InputMap
provides a binding between an input event (currently onlyKeyStroke
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
Constructors[InputMap](#%3Cinit%3E%28%29)()
Creates an InputMap
with no parent and no mappings.
Method Summary
[allKeys](#allKeys%28%29)()
Returns an array of the KeyStroke
s defined in thisInputMap
and its parent.void
[clear](#clear%28%29)()
Removes all the mappings from this InputMap
.
Returns the binding for keyStroke
, messaging the parent InputMap
if the binding is not locally defined.[getParent](#getParent%28%29)()
Gets this InputMap
's parent.[keys](#keys%28%29)()
Returns the KeyStroke
s that are bound in this InputMap
.void
Adds a binding for keyStroke
to actionMapKey
.void
Removes the binding for key
from this InputMap
.void
Sets this InputMap
's parent.int
[size](#size%28%29)()
Returns the number of KeyStroke
bindings.
Methods declared in class java.lang.Object
[clone](../../../java.base/java/lang/Object.html#clone%28%29), [equals](../../../java.base/java/lang/Object.html#equals%28java.lang.Object%29), [finalize](../../../java.base/java/lang/Object.html#finalize%28%29), [getClass](../../../java.base/java/lang/Object.html#getClass%28%29), [hashCode](../../../java.base/java/lang/Object.html#hashCode%28%29), [notify](../../../java.base/java/lang/Object.html#notify%28%29), [notifyAll](../../../java.base/java/lang/Object.html#notifyAll%28%29), [toString](../../../java.base/java/lang/Object.html#toString%28%29), [wait](../../../java.base/java/lang/Object.html#wait%28%29), [wait](../../../java.base/java/lang/Object.html#wait%28long%29), [wait](../../../java.base/java/lang/Object.html#wait%28long,int%29)
Constructor Details
InputMap
public InputMap()
Creates anInputMap
with no parent and no mappings.Method Details
setParent
public void setParent(InputMap map)
Sets thisInputMap
's parent.
Parameters:
map
- theInputMap
that is the parent of this onegetParent
Gets this
InputMap
's parent.
Returns:
map theInputMap
that is the parent of this one, or null if thisInputMap
has no parentput
Adds a binding for
keyStroke
toactionMapKey
. IfactionMapKey
is null, this removes the current binding forkeyStroke
.
Parameters:
keyStroke
- aKeyStroke
actionMapKey
- an action map keyget
Returns the binding for
keyStroke
, messaging the parentInputMap
if the binding is not locally defined.
Parameters:
keyStroke
- theKeyStroke
for which to get the binding
Returns:
the binding forkeyStroke
remove
Removes the binding for
key
from thisInputMap
.
Parameters:
key
- theKeyStroke
for which to remove the bindingclear
public void clear()
Removes all the mappings from thisInputMap
.keys
Returns the
KeyStroke
s that are bound in thisInputMap
.
Returns:
an array of theKeyStroke
s that are bound in thisInputMap
size
public int size()
Returns the number ofKeyStroke
bindings.
Returns:
the number ofKeyStroke
bindingsallKeys
Returns an array of the
KeyStroke
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 theKeyStroke
s defined in thisInputMap
and its parent