Formatting text Fields
I want to have text fields formatted in the following way:
date YYYY-MM-DD
phone (XXX) 555-5555
I know that I can have for example:
new JFormattedTextField(newnew simpleDateFormat("yyyy-MM-dd"));
But I want the dashes to be permanently in the text field and as a user types the date the prompt moves over to the next spot automatically. The same goes for the phone number .
So for example: Initially I see "- - " Then I start typing:
"200 - - " -> "2007-0 - ". I guess I've been clear enough.
There is a lot of forms like this on the internet
[726 byte] By [
aurir_a] at [2007-11-26 18:07:14]

# 1
Nevermind, I got it:
javax.swing.text.MaskFormatter fmt = null;
// A phone number
try {
fmt = new javax.swing.text.MaskFormatter("###-###-####");
} catch (java.text.ParseException e) {
}
ftfPhone = new JFormattedTextField(fmt);
# 2
The formatting works really nice BUT:
I have a "reset" button which should reset the whole form. It calles a reset() which uses
tftSSNum.setText("");
It does clear the form, but if I click on SS# field and then click on any other it reverts the previous value. No doubt, it can contribute to many errors. How do I clear JFormattedTextFileds so that values entered are gone forever?