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
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.
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?