• 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

Override Java Component keystrokes

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to our GUI forum.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic