Thanks, Jeanette!
Yes, that really helps explain the differences I've been seeing.
One other significant feature of the registerKeyboardAction/inputMap
approach is that Keystoke actions appear to be consumed by the component
they are registered with.
For instance, I have a panel of JButtons, each of them registered for the
TAB keystroke. (I did not register them myself. They appear to registered by
the underlying UI delegate). The buttons reside in a JPanel which is also
registered for the TAB keystroke (under the condition of
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT since it never gets focus
directly). The problem is that the JPanel never detects the TAB key input.
It seems to detect any *other* key registration *except* those that are
registered to the button. Is the JButton consuming the keystroke? If so, any
suggestions for allowing them to be intercepted by the JPanel?
BTW, here's the URL from the Swing Connection, in case anyone else is
interested. It applies to JDK 1.3.
http://java.sun.com/products/jfc/tsc/special_report/kestrel/keybindings.html
-----Original Message-----
From: Kleopatra [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 01, 2001 6:53 AM
Cc: [EMAIL PROTECTED]
Subject: Re: registerKeyboardAction vs. addKeyListener
pfarwell schrieb:
>
> What are the relative advantages or disadvantages of using
> JComponent registerKeyboardAction() versus Component
> addKeyListener()? (According to the javadocs
> registerKeyboardAction() has been replaced by getInputMap().put
> () and getActionMap().put() - but as far as I can tell these are
> functionally equivalent to registerKeyboardAction).
They are different: KeyListeners are near to lowest level processing,
disadvantage is that you have to do a lot of work yourself, advantage is
that listeners are the first in line to see the events. Note that you
they get only events from focused components.
Actions associated with keyStrokes are higher level, and as such easier
to handle. You just have to define the state of the keystroke that
should trigger some action, then the system does all the bookkeeping for
you. Disadvantage might be that keybindings are the last in line to see
the events. Advantage is handling of keystrokes in Components even if
they are not focused.
On the whole I nearly never use KeyListeners but very often use
KeyBindings.
There is a very good article at the swing connection from Jan: Keyboard
Bindings in Swing. It's more about differences between the old
registerkeyboardAction vs. the new inputMap/actionMap but I found it
extremely interesting.
Greetings
Jeanette
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing