Sending Keyboard Events to Background Window

Discussion in 'Java' started by Chris Share, Oct 23, 2007.

  1. Chris Share

    Chris Share Guest

    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
     
    Chris Share, Oct 23, 2007
    #1
    1. Advertising

  2. 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.aspx/java-general/200710/1
     
    Andrew Thompson, Oct 23, 2007
    #2
    1. Advertising

  3. Chris Share

    Chris Share Guest

    > 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
     
    Chris Share, Oct 23, 2007
    #3
  4. 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.aspx/java-general/200710/1
     
    Andrew Thompson, Oct 23, 2007
    #4
  5. Create one keylistener class and add it to all the windows.

    "Chris Share" <> wrote in message
    news:...
    >> 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
    >
     
    G. Garrett Campbell, Oct 23, 2007
    #5
  6. In article <>,
    Chris Share <> 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.pvv.org/~bcd
    powered by emacs
     
    Bent C Dalager, Oct 23, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Haider Kazmi

    SWING keyboard events

    Haider Kazmi, Jul 13, 2003, in forum: Java
    Replies:
    2
    Views:
    1,028
    Todd Blackley
    Jul 18, 2003
  2. Replies:
    0
    Views:
    349
  3. Replies:
    2
    Views:
    503
    Thomas Fritsch
    Feb 7, 2005
  4. Ziv Forshtat
    Replies:
    3
    Views:
    436
    Josiah Carlson
    Feb 4, 2004
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    373
    Chris
    Aug 30, 2005
Loading...

Share This Page