Why do we have to use the extra object ActionMap
?
What's the meaning?
Take this as an example:
imap.put(KeyStroke.getKeyStroke("ctrl Y"), "panel.yellow");
ActionMap amap = panel.getActionMap();
amap.put("panel.yellow", yellowAction);
Why do we have to use the extra object ActionMap
?
What's the meaning?
Take this as an example:
imap.put(KeyStroke.getKeyStroke("ctrl Y"), "panel.yellow");
ActionMap amap = panel.getActionMap();
amap.put("panel.yellow", yellowAction);
As shown in this example, an InputMap
associates a KeyStroke
with an abstract name that identifies the correspoding Action
. The ActionMap
uses that name as a key to evoke a particular Action
instance's actionPerformed()
method. As a concrete example, this ScrollTimer
uses the ActionMap
of a JScrollPane
to look up actions by name and use them without direct access to the implementation.
Addendum: The abstraction was designed to support the "pluggable look and feel" (L&F) architecture describe here.