Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Sending Keyboard Events to Background Window

Thread view: 
Chris Share - 23 Oct 2007 03:46 GMT
Hi,

I'm developing an application that consists of three windows
(JFrames). Only one of the JFrames handles keyboard input.

At present, if I move one of the other JFrames to the front the
keyboard control stops. I assume that the front JFrame is getting the
keyboard focus.

I'd like to be able to move one of the other JFrames to the front but
still send the key commands to the back window.

How can I do this?

I've tried using frame.setFocusable(false); however this doesn't seem
to make any difference.

Cheers,

Chris
Andrew Thompson - 23 Oct 2007 04:23 GMT
...
>I'm developing an application that consists of three windows
>(JFrames). Only one of the JFrames handles keyboard input.
[quoted text clipped - 5 lines]
>I'd like to be able to move one of the other JFrames to the front but
>still send the key commands to the back window.

Why?  What would this ability offer to me the end user
(besides being very confusing)?

>How can I do this?

Try adding the first frame to the second frame's KeyListener.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Chris Share - 23 Oct 2007 05:20 GMT
> Why?  What would this ability offer to me the end user
> (besides being very confusing)?

The app displays the same data in various formats (2D, 3D, etc.). To
the user, it actually doesn't matter which window is at the front, as
long as the keyboard controls still function.

Cheers,

Chris
Andrew Thompson - 23 Oct 2007 09:17 GMT
>> Why?  What would this ability offer to me the end user
>> (besides being very confusing)?
>
>The app displays the same data in various formats (2D, 3D, etc.). To
>the user, it actually doesn't matter which window is at the front, as
>long as the keyboard controls still function.

(slaps forehead)  Keyboard shortcuts and accelerators!
Of course, how silly of me to forget.

I'd be interested to hear how you go with my suggestion.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

G. Garrett Campbell - 23 Oct 2007 14:50 GMT
Create one keylistener class and add it to all the windows.

>> Why?  What would this ability offer to me the end user
>> (besides being very confusing)?
[quoted text clipped - 6 lines]
>
> Chris
Bent C Dalager - 23 Oct 2007 15:04 GMT
>Hi,
>
[quoted text clipped - 9 lines]
>
>How can I do this?

If you have your own custom key listeners already, then attach them to
all the frames rather than just one of them. If, on the other hand,
you just want the standard Swing stuff to happen, but happen to a
non-focused frame, you could experiment with the following.

I think I have seen various hackish ways of redirecting events in
Swing code that would pass events to different components by calling
e.g. processKeyEvent on them. You might override
JFrame.processKeyEvent on the frames that are not to handle key
presses and implement them along the lines of
processKeyEvent(KeyEvent e) { mainFrame.processKeyEvent(e); }

I don't know if you would have to massage the KeyEvent before passing
it on in this manner though.

Results may vary :-)

(Of course, there must be a better way to do this - I just can't think
of one atm ...)

Cheers,
    Bent D
Signature

Bent Dalager - bcd@pvv.org - http://www.pvv.org/~bcd
                                   powered by emacs



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.