• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Two JPanels in a JFrame listening to keyboard events

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic