Skip to main content

Validation JTextField

2 replies [Last post]
marcoap
Offline
Joined: 2003-08-18
Points: 0

Hi,

Does anybody knows which the best pratice for validate the input information in a JTextField???

Is there a component free for this validation???

Thanks!!!!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alex_spb
Offline
Joined: 2006-02-17
Points: 0

Have a look at JFormattedTextField, it can validate input data

Also check the following article
http://java.sun.com/products/jfc/tsc/articles/reftf/index.html

it shows how to create RegexFormatter which allows using regular expressions for validation

If you dont want to use JFormattedTextField you can subclass PlainDocument class which would validate data using regexp or whatever and set it to your textfields

see JTextField in javadoc for example
and JTextField.setDocument(Document doc)

good luck

Scott Violet

In addition to JFormattedTextField and a custom PlainDocument you could
also create a custom DocumentFilter. While DocumentFilter was primarily
designed for JFTF it can be used on it's one. Creating a custom
DocumentFilter is a bit lighter weight than creating a custom Document.

-Scott