JFormattedTextField : Java Glossary


A tool in Java version 1.4 or later to let you format output and input. JFormattedTextField needs the auxiliary help of MaskFormatter to key phone numbers (250) 361-9093, Zip+4, credit card numbers etc. It needs the help of NumberFormatter and DecimalNumberFormat to deal with numbers. These in turn rely on Documentfilters and NavigationFilters. However, out the box, the fool thing is too dumb to even stop the user from entering alpha characters into a numeric field. Think of it as a complicated Lego set to create usable data entry classes. It works typically by doing a validation when a the component loses focus. I have never heard anyone wax enthusiastically about it. For true keystroke-level validation you may have to write your own from scratch. There is no AWT (Advanced Windowing Toolkit) equivalent, at least in the standard class Library.

You might have more success with AbstractDocument.setDocumentFilter( DocumentFilter ) where you implement a custom DocumentFilter to limit input.

Learning More

Oracle’s Javadoc on JFormattedTextField class : available:
Oracle’s Javadoc on DocumentFilter class : available:

This page is posted
on the web at:


Optional Replicator mirror
of mindprod.com
on local hard disk J:

Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

Your face IP:[]
You are visitor number