Results 1 to 3 of 3
  1. #1
    sim18 is offline Member
    Join Date
    Oct 2011
    Posts
    30
    Rep Power
    0

    Default KeyListener needs to grab focus!

    Hi, thanks in advance to anybody who can help me.

    I have two JPanels and a JFrame, I have finally got my image to move on one of the JPanels by using :

    Java Code:
    cp.addKeyListener(myAnimationPanel);
    		cp.requestFocusInWindow();
    &&

    Java Code:
    addKeyListener(this);
    		this.requestFocus();
    When I load up my program and move the image with arrow keys everything is perfect. THEN i click on a button that is in another JPanel, and now my image loses focus and I cant move it again with the arrow keys :/

    Hope somebody can help me

  2. #2
    sim18 is offline Member
    Join Date
    Oct 2011
    Posts
    30
    Rep Power
    0

    Default Re: KeyListener needs to grab focus!

    Sorry not sure how to delete this thread, literally just figured it out!!

    for anybody else having these problems in the paint method put requestFocus(true);

    Woo!

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,015
    Blog Entries
    7
    Rep Power
    20

    Default Re: KeyListener needs to grab focus!

    It's appreciated that you left a clue to the solution of your problem. Some people edit away their original question and leave the entire thread useless for others; thanks and good luck.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. A KeyListener that doesn't require focus
    By vaano in forum New To Java
    Replies: 3
    Last Post: 11-14-2011, 09:46 PM
  2. Replies: 4
    Last Post: 10-30-2011, 06:52 AM
  3. how to grab info from array
    By skuzzie in forum New To Java
    Replies: 3
    Last Post: 12-09-2010, 01:26 PM
  4. grab the textfile
    By Sticks_ll in forum New To Java
    Replies: 3
    Last Post: 03-31-2009, 01:23 PM

Posting Permissions

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