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 http://developer.java.sun.com/developer/TechTips/1999/tt1005.html 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