JFormattedTextField : Java Glossary

JFormattedTextField
A tool inJava 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:

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/jformattedtextfield.html J:\mindprod\jgloss\jformattedtextfield.html
logofeedback Please email your feedback for publication, letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email If you want your message kept confidential, not considered for posting, please explicitly specify that.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.213]
You are visitor number 16,275.