This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Value of text field after each key typed  RSS feed

 
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: 2800
15
  • 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
Boost this thread!