Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Value of text field after each key typed

 
Poorav Chaudhari
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Camick
Ranch Hand
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to get the value of a text field after every key is typed.


Use a DocumentListener, NOT a KeyListener.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic