I couldn't find a concise answer about the relationships among all these, so that I can pick up best practices and get going. JTextComponent
has:
The old
addKeyListener(..)
. We write aKeyListener
with methods that get called onkeyPressed(..)
,keyTyped(..)
, etc. events, which we can query:event.getKeyCode()
.addKeymap(..)
andsetKeymap(..)
. AKeymap
hasaddActionForKeyStroke(..)
, which takes aKeyStroke
(that we can get by callingKeyStroke
's static methods specifying the character or key code), and anAction
, which is anActionListener
with bells and whistles.getInputMap(..)
andgetActionMap(..)
. AnInputMap
maps aKeyStroke
(as above) to aString
, and theActionMap
maps the string to anAction
(as above). The Java Tutorial How to use key bindings talks about that.
These are three redundant ways of attaining the same functionality. Besides comparative advantages/disadvantages, this raises the natural question of how these three mechanisms co-exist? Which ones take priority over others?