wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JTextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextField" Watch "JTextField" New topic
Author

JTextField

jacq carballo
Ranch Hand

Joined: Feb 10, 2002
Posts: 42
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

Joined: Jan 13, 2002
Posts: 732
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

Joined: May 17, 2001
Posts: 2823
Actualy with JTextField you use Documents. Here is a link to the the tutorial on JTextField.
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
sorry. you are right Paul.
missed the J

thanks for correcting me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextField