JTextArea actionlistener that goes off after input

hello,

i want to get the text from a JTextArea every time a letter is entered (or something is copied to it). I have used the KeyTyped actionlistener until now, but i noticed that it is always one letter to late, that is, when i write this code

Textarea.addKeyListener(new java.awt.event.KeyAdapter(){

publicvoid keyTyped(java.awt.event.KeyEvent evt){

System.out.println(Textarea.getText());

}

});

it will print out the text that was in the textfield BEFORE the last letter was typed. my question is, how can i retrieve the text in a textfield AFTER the last input?

hope you know the answer,

cheers, felix

[872 byte] By [Regenspazierganga] at [2007-11-26 15:14:19]
# 1

evt.getKeyChar()

~Tim

EDIT:

I guess that doesn't actually answer the question, but if you store this in a stringbuffer, and append every character, you will have all the keys entered. Of course, you won't necessarily have the modifiers, and the like, Look at the KeyEvent API for more info.

SomeoneElsea at 2007-7-8 9:05:52 > top of Java-index,Java Essentials,Java Programming...
# 2
Swing related questions should be posted in Swing forum.Read the tutorial: http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html#doclisteners
Rodney_McKaya at 2007-7-8 9:05:52 > top of Java-index,Java Essentials,Java Programming...
# 3

thanks for your reply!

but i think that gives invalid keys (like backspace) as well ...

i have just found the following text in the usenet:

"It's almost always a mistake to try to interpret the contents of a

JTextField by looking at key events. It's more practical to use the

Document of the JTextField. In particular, add a DocumentListener to

the Document. This will be called when the contents of the field

changes in any way, whether by typing characters, erasing characters,

or pasting characters (didn't think about that one, did you?). "

so my question is now, how do i do that?

Regenspazierganga at 2007-7-8 9:05:52 > top of Java-index,Java Essentials,Java Programming...
# 4
Great! Thanks a lot, Rodney!
Regenspazierganga at 2007-7-8 9:05:52 > top of Java-index,Java Essentials,Java Programming...