File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
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: 2226
    
    8
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://aspose.com/file-tools
 
subject: Value of text field after each key typed