Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Sending Keyboard Events to Background Window

Reply
Thread Tools

Sending Keyboard Events to Background Window

 
 
Chris Share
Guest
Posts: n/a
 
      10-23-2007
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

 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      10-23-2007
Chris Share wrote:
...
>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.


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.

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

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.asp...neral/200710/1

 
Reply With Quote
 
 
 
 
Chris Share
Guest
Posts: n/a
 
      10-23-2007
> 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

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      10-23-2007
Chris Share wrote:
>> 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.

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

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.asp...neral/200710/1

 
Reply With Quote
 
G. Garrett Campbell
Guest
Posts: n/a
 
      10-23-2007
Create one keylistener class and add it to all the windows.

"Chris Share" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>> 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
>



 
Reply With Quote
 
Bent C Dalager
Guest
Posts: n/a
 
      10-23-2007
In article <(E-Mail Removed) om>,
Chris Share <(E-Mail Removed)> wrote:
>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?


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
--
Bent Dalager - http://www.velocityreviews.com/forums/(E-Mail Removed) - http://www.pvv.org/~bcd
powered by emacs
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Background transparent when 'background' is used JWL HTML 4 09-26-2006 05:37 PM
Background Check - Background search - People search mason66 ASP .Net 0 07-27-2006 10:20 AM
Events Events Events Please Help Chris ASP .Net Web Controls 0 08-30-2005 08:21 PM
Keyboard error or no keyboard present??? Bud Light Computer Support 2 01-22-2005 04:00 AM
Sending form info from popup window to original window Person Javascript 1 10-21-2003 09:38 PM



Advertisments