- java.lang.Object
-
- javax.swing.InputMap
-
- All Implemented Interfaces:
- Serializable
- Direct Known Subclasses:
- ComponentInputMap, InputMapUIResource
public class InputMap extends Object implements Serializable
InputMap
provides a binding between an input event (currently onlyKeyStroke
s are used) and anObject
.InputMap
s are usually used with anActionMap
, to determine anAction
to perform when a key is pressed. AnInputMap
can have a parent that is searched for bindings not defined in theInputMap
.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 Constructor and Description InputMap()
Creates anInputMap
with no parent and no mappings.
-
Method Summary
Methods Modifier and Type Method and Description KeyStroke[]
allKeys()
Returns an array of theKeyStroke
s defined in thisInputMap
and its parent.void
clear()
Removes all the mappings from thisInputMap
.Object
get(KeyStroke keyStroke)
Returns the binding forkeyStroke
, messaging the parentInputMap
if the binding is not locally defined.InputMap
getParent()
Gets thisInputMap
's parent.KeyStroke[]
keys()
Returns theKeyStroke
s that are bound in thisInputMap
.void
put(KeyStroke keyStroke, Object actionMapKey)
Adds a binding forkeyStroke
toactionMapKey
.void
remove(KeyStroke key)
Removes the binding forkey
from thisInputMap
.void
setParent(InputMap map)
Sets thisInputMap
's parent.int
size()
Returns the number ofKeyStroke
bindings.
-
-
-
Method Detail
-
setParent
public void setParent(InputMap map)
Sets thisInputMap
's parent.- Parameters:
map
- theInputMap
that is the parent of this one
-
getParent
public InputMap getParent()
Gets thisInputMap
's parent.- Returns:
- map the
InputMap
that is the parent of this one, or null if thisInputMap
has no parent
-
put
public void put(KeyStroke keyStroke, Object actionMapKey)
Adds a binding forkeyStroke
toactionMapKey
. IfactionMapKey
is null, this removes the current binding forkeyStroke
.
-
get
public Object get(KeyStroke keyStroke)
Returns the binding forkeyStroke
, messaging the parentInputMap
if the binding is not locally defined.
-
remove
public void remove(KeyStroke key)
Removes the binding forkey
from thisInputMap
.
-
clear
public void clear()
Removes all the mappings from thisInputMap
.
-
keys
public KeyStroke[] keys()
Returns theKeyStroke
s that are bound in thisInputMap
.
-
size
public int size()
Returns the number ofKeyStroke
bindings.
-
allKeys
public KeyStroke[] 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.
-
-
Document created the 11/06/2005, last modified the 04/03/2020
Source of the printed document:https://www.gaudry.be/en/java-api-rf-javax/swing/InputMap.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.