Results 1 to 2 of 2
  1. #1
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Unsure of whether to use key bindings

    My app has two text input components, a terminal and a chat window. Right now I'm using key listeners so that whichever component has focus receives key typed events. This works, but it's potentially a little confusing if neither component has focus.

    So what I'd like is for the chat window to receive key events when it has focus, and the terminal to receive key events when it or anything else other than the chat window has focus.

    Can I do this with key bindings? I've never used them directly (I understand they're used for accelerators and mnemonics and stuff like that) and I'm a little confused about them. Is there an easy way to set up key bindings for "any key", or would I need to create a binding for every key I want my terminal to accept?
    Get in the habit of using standard Java naming conventions!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Unsure of whether to use key bindings

    There are three input maps. Judicious selection (and experimenting) should get you what you want.

    Is there an easy way to set up key bindings for "any key"
    Not that I know of.

    or would I need to create a binding for every key I want my terminal to accept?
    I would use a KeyListener. maybe on the glassPane if I need to capture a keyPressed anywhere in the GUI, although some work might be needed to forward KeyEvents.

    db
    Last edited by DarrylBurke; 04-15-2012 at 08:45 AM.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. can one disable key bindings on a JComponent?
    By gib65 in forum AWT / Swing
    Replies: 2
    Last Post: 10-14-2010, 05:44 PM
  2. Replies: 1
    Last Post: 04-01-2010, 06:14 PM
  3. JAXB Bindings - error while compiling Schema(s)
    By Stipejava in forum NetBeans
    Replies: 0
    Last Post: 10-30-2009, 01:15 PM
  4. [SOLVED] Key listener, unsure abt the tab key
    By dbashby in forum New To Java
    Replies: 7
    Last Post: 04-16-2009, 06:49 AM
  5. genesis 3.0-RC2: Swing, SWT and Thinlet bindings
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-24-2007, 11:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •