Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextField

 
jacq carballo
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to validate the data in the JTextField. I only want the user to input numeric values. But i want to be able to trap the key as soon as the key is released. If it is numeric, then it is displayed on the screen. otherwise, whatever is typed is not displayed on the screen anymore. TIA
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
add a TextListener for the textField.
then override the method textValueChanged(TextEvent e).
check for the value that changed. if it is a number continue, otherwise use the consume method to do nothing.
hope it helps.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actualy with JTextField you use Documents. Here is a link to the the tutorial on JTextField.
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry. you are right Paul.
missed the J

thanks for correcting me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic