• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Override Java Component keystrokes

 
Ralf Butler
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I want to make my application responding to keystrokes. But it seems that some keystrokes are swallowed by other components. I use a top level component to capture all keystrokes:

This approach works fine for many keystrokes like CTRL+SHIFT+A or CTRL+SHIFT+B. However, I now want to capture CTRL+SHIFT+RIGHT. Can it be that it is swallowed by a jTree which has the focus? It is for sure not captured by the OS because the KeyListener example (http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html) works fine and captures exactly this keystroke.

Help is much appreciated,
Ralf
 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our GUI forum.
 
Rob Camick
Ranch Hand
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But it seems that some keystrokes are swallowed by other components

Can it be that it is swallowed by a jTree which has the focus?


Correct, Key Bindings for components with focus take precedence over other bindings. In case you are interested in all the default bindings you can check out Key Bindings.

Global Event Listeners may help with a solution.
 
Ralf Butler
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

Very interesting blog entries. So I understand that I can capture keyboard events by using AWTEventListener. But what I still don't get is how to capture a particular keystroke, like the "Left" keystroke for example. In addition the "Left" keystroke should not be forwarded to the Jtree component. Do you have a little example for that?

Thank you,
Ralf
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic