Results 1 to 3 of 3
  1. #1
    nikkka is offline Member
    Join Date
    Mar 2011
    Posts
    45
    Rep Power
    0

    Default JTextArea's KeyListener' overloaded method works only once... what can be a problem?

    I have a KeyListener added to JTextPane that is supposed to react when SPACE is pressed. I have this code, but it works only for one space...
    Java Code:
    		@Override public void keyReleased(KeyEvent e) {
    			if(e.getKeyCode()==KeyEvent.VK_SPACE)
    				System.out.println("SPACE is pressed!");
    		}
    Now, when I enter "asdf " it reacts properly, but if I continue typing and go "asdf asdf " than nothing happens... Why? I mean, it should react on second space, shouldn't it? :S

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    I think you are going to have to post an SSCCE that demonstrates the problem, as this may not be enough information to deduce the problem. Further, while its not clear what your goal is with the KeyListener, a JTextComponent has other means through which to track user changes which might be more appropriate and flexible (DocumentListener, CaretListener, custom Document, etc...)

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

Similar Threads

  1. Replies: 9
    Last Post: 11-04-2011, 03:09 AM
  2. RecordControl commit() method works only once
    By cartoon_20 in forum CLDC and MIDP
    Replies: 0
    Last Post: 10-31-2010, 11:02 PM
  3. Replies: 6
    Last Post: 03-11-2009, 04:38 PM
  4. how compareTo Method works
    By nanaji in forum Advanced Java
    Replies: 1
    Last Post: 06-22-2008, 07:40 PM
  5. Overloaded method
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:42 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
  •