Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how does JMenuItem capture keyboard input?

829050Apr 5 2011 — edited Apr 10 2011
Dear all,

I am a bit of a keyboard fanatic and would like all apps to be able to function without any mouse usage and probably without any menu usage. I am currently designing a module to present the user at any given time with a clear snapshot of all the hotkeys and Actions available at any one time - including everything, focus traversal keys, etc, ... e.g. it involves an exploration of the InputMap and ActionMap structures associated with JComponents.

But I'd like to be able to "harness" whatever mechanism JMenuItems use to capture keyboard input for the mnemonics and also for the accelerators. At first I assumed this was something to do with the mysterious "glass pane"... but having looked into the latter a bit this doesn't seem to be so: a glass pane hanging off a JRootPane hanging off a JFrame (for example) has to be given all sorts of functionality explicitly before it does anything vaguely useful.

Say you have a JTree sitting in a JScrollPane sitting in a JPanel sitting in the content pane of a JFrame. The keyboard input when the JTree has focus is consumed by the JTree... but if you have set up an accelerator for a JMenuItem the latter mysteriously bypasses the JTree's otherwise strong ability to grasp all keyboard entry and deny it to all and sundry.

So how does the JMenuItem do this?

Thanks if you can enlighten me.

Mike
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 8 2011
Added on Apr 5 2011
8 comments
282 views