Results 1 to 3 of 3
  1. #1
    gib65 is offline Member
    Join Date
    Jun 2010
    Posts
    86
    Rep Power
    0

    Default disabling JFrame's response to spacebar

    How can I get a JFrame to stop responding to the spacebar? I'm programming a video game and I want to use the spacebar for firing. I'm using key binding for all responses to key strokes. I just added the spacebar to my bindKeys() method and it didn't respond the same way the other keys did. I soon realized the reason is because the JFrame seems to have priority over the spacebar and it uses it to activate whichever component has the focus. I have a few buttons and I tested this by pressing tab and then seeing if the spacebar had a different response - and it did. I don't really need the JFrame to respond to the spacebar in this way, so I'm looking for a way to disable its responding to it. Is this possible?

  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

    You can try setFocusable(false) for the buttons.

    db

  3. #3
    gib65 is offline Member
    Join Date
    Jun 2010
    Posts
    86
    Rep Power
    0

Similar Threads

  1. Automatic Content Assist (no CTRL+SPACEBAR)
    By dnikolov in forum Eclipse
    Replies: 3
    Last Post: 12-19-2011, 06:02 PM
  2. Disabling Buttons
    By superpala in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-26-2010, 11:00 PM
  3. Disabling Bluetooth passkey
    By lambi in forum Sun Java Wireless Toolkit
    Replies: 0
    Last Post: 12-29-2009, 02:33 PM
  4. Disabling a button at EOF
    By dbashby in forum New To Java
    Replies: 1
    Last Post: 03-10-2009, 03:37 PM
  5. disabling JButtons after win in TicTacToe
    By noisepoet in forum New To Java
    Replies: 1
    Last Post: 05-19-2007, 12:01 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
  •