File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Two JPanels in a JFrame listening to keyboard events Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Two JPanels in a JFrame listening to keyboard events" Watch "Two JPanels in a JFrame listening to keyboard events" New topic
Author

Two JPanels in a JFrame listening to keyboard events

Antonio Ruffolo
Greenhorn

Joined: Jun 28, 2011
Posts: 2
I made a SSCEE code wich explain my problem. There are two JPanels, when I press the arrow key "up" I want to do something in both of them, with the code below only one panel react to the arrow key! Do you know why? can you show me a code wich works?

Here is the code, just copy and paste and see it yourself.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
it seems the keyEvent is consumed by the last component added.

you may have to add a holding panel for both panels, use it's input/action map
to fire off an event to both panels
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Two JPanels in a JFrame listening to keyboard events