keyListener and JTextField problem

I'm a student who's studying java rite now,

i found this problem while i'm playing with GUI.

i made a JTextField and added keyListener on it

public void keyTyped(KeyEvent e){

String typed = searchName.getText(); //searchName is the JTextField

System.out.println("test "+typed);

searchName.requestFocusInWindow();

}

then i type "ABC"

when i type "A"

instead of "test A" message that i'm looking for, i'm getting "test " massage

when i type "B" after "A"

I'm getting "test A" massage instead of "test AB"

when i type "A"

instead of "test A" message that i'm looking for, i'm getting "test " massage

when i type "B" after "A"

I'm getting "test A" massage instead of "test AB"

can u guys help me solve this problem? T_T

[833 byte] By [Triplecounta] at [2007-11-27 5:34:26]
# 1
It looks like you are getting the keyTyped event before the value in the textfield is actually updated.Use the keyReleased event in stead.
gimbal2a at 2007-7-12 15:02:35 > top of Java-index,Desktop,Core GUI APIs...
# 2
A better solution is to use a [url http://java.sun.com/docs/books/tutorial/uiswing/events/documentlistener.html]Document Listener[/url].
camickra at 2007-7-12 15:02:35 > top of Java-index,Desktop,Core GUI APIs...
# 3
PROBLEM SOLVED!!!<3 u guys
Triplecounta at 2007-7-12 15:02:35 > top of Java-index,Desktop,Core GUI APIs...