• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

KeyAdapter Masking Problem  RSS feed

Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears that a KeyAdapter registered on a JFrame is masking a KeyAdapter registered on a JPanel contained within the JFrame. I seem to be unable to trap for KeyEvents from the JPanel.
I have an application which consists of a single frame and a cardlayout, which put's the application's panels on top. Normally, there is a KeyAdapter attached to the top frame, which traps for CTL+D and does something. I need one of the panels to trap CTL+D instead. I attempted to add a KeyListener to the panel, however it does not seem to be intercepting the keystrokes.
It appears that this is because the Panel does not have the focus, even though the components within it *do* have the focus. I say this becuase even when I change the key combo to a non-conflicting value (e.g. CTL+F) nothing appears to happen.
One solution is to add an API to the Panel that returns a KeyAdapter, and have the Frame obtain this KeyAdapter when the context changes. But this would replace the original KeyAdapter, rather than augment it. There are ways to design around this, but it seems messy to me.
Another solution is to use a KeyStroke/Action map. First, this would require re-writing old code. Second, I am not very familiar with this process. There is a helpful link at
however it isn't clear how this would work.
Has anyone encountered this issue before?
Blueberry pie is best when it is firm and you can hold in your hand. Smell it. And smell this tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!