This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Value of text field after each key typed Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Value of text field after each key typed" Watch "Value of text field after each key typed" New topic
Author

Value of text field after each key typed

Poorav Chaudhari
Ranch Hand

Joined: Sep 17, 2002
Posts: 50
Hi,

I want to get the value of a text field after every key is typed. So, say the text field already has
hello
if i type '!' at the end, txtfield.getText() still gives me hello for the keyTyped event instead of hello! txtfield.getText() + event.getKeyChar() gives the correct value, but the problem with using this approach is that supposing I highlight the entire hello string and type something else like 'w' the above code will return hellow instead of w.

Why does it seem so difficult to get the value of a textfield after a keystroke?

Please help.

thanks


Poorav Chaudhari
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 1788
    
    2
I want to get the value of a text field after every key is typed.


Use a DocumentListener, NOT a KeyListener.

 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Value of text field after each key typed
 
Similar Threads
Charset missing
Whats the best way ??
JTextField
KeyListener && KeyEvents
Tab Key Binding JTextField