JFormattedTextField : Java Glossary

JFormattedTextField
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:

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
logo
Please email your , 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, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, please quote it and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. Threatening to kill me or spouting obscenities has yet to persuade me to change my mind.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.213]
You are visitor number 16,487.