Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2004

Tip: Looking for answers? Try searching our database.

Multiple actions for a single key press

Thread view: 
Will Friedman - 30 Mar 2004 22:30 GMT
Hi all,

I'm writing an UI that uses F1-F10 for its actions and have set up key
bindings for each of them.  One particular action requires that the
immediately following input (F1-F10) do a new action in addition to
its regularly assigned action, but I'm having a devil of a time
figuring out how to do this.  The most logical way it seemed would be
to (temporarily) assign multiple actions to each of the key bindings,
but it appears that InputMap & ActionMap's put() method overrides the
old binding instead of adding an _extra_ binding, which is what I
would have hoped would happen.

I then thought to assign the new action to all the keys which would in
the end rebind the keys to their old bindings and then manually run
the action associated with pressed key, but I can't figure out a way
to find out what the pressed key was!  I thought to use ActionEvent's
getActionCommand() method, but that returns null for some reason.  I
also thought to add a KeyListener which would add the pressed key to a
private variable, but doing so consumes all keyboard input such that
the actions associated with the bindings never happen at all!

Any help or ideas would be greatly appreciated.

Thank you,

Will
Will Friedman - 31 Mar 2004 08:58 GMT
Although I know it's very bad form to reply to one's own message, I
want to update my original post with some new information.  I was able
to get key bindings to work with a KeyListener -- turns out that my
problem was setting the focus incorrectly.  My two main questions
stand, which are:

Is there any way to assign multiple actions to a single key using key
bindings? (InputMap, ActionMap, etc.)?

Why does running getActionCommand() on the ActionEvent passed into an
action triggered by a key binding return null instead of either a
KeyEvent or KeyStroke?

Thanks,

Will


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.