SWING keyboard events

H

Haider Kazmi

Need a nudge in the right direction :)

Is there a way to get the keyboard events from the entire UI without adding
keyboard adapters to every component on the Frame.

cheers
Haider
 
B

Babu Kalakrishnan

Need a nudge in the right direction :)

Is there a way to get the keyboard events from the entire UI without adding
keyboard adapters to every component on the Frame.

Your topmost frame (or the current active window if you have multiple
native windows/frames/dialogs) is where these events first arrive from
the native windowing system. Overriding the processKeyEvent method of
these JFrames / JDialogs/ JWindows will allow you to have a first look
at the event. (Don't forget to call super.processKeyEvent method to
dispatch it normally if you aren't handling it).

By the way, if you're using swing, KeyListeners aren't normally the
right approach. Take a look at the InputMap/ActionMap architecture.

BK
 
T

Todd Blackley

Yes, but I'm at home now and don't have the code. There are options for the
current window, and all sub-Windows, etc. Please search in java.sun.com

Todd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top