java - JFormattedTextField set value and text null after inputting wrong format -
i'm working java application jformattedtextfield. have problems that:
how set jformattedtextfield can accept "/" , "-"
i want set jformattedtextfield value , text null or "" after entering wrong format.
example:
2.1.jformattedtextfield ftf .... format ("yyyy-mm-dd")
2.2. input right format: 1990-5-6
2.3. leave ftf
2.4. focus ftf , input wrong format: 5-6-1990
2.5. leave ftf recognize wrong format return else
but want must null or empty.
how can it?
any suggestions appreciated!
this first answer on forum , hope don't mess up. first question, can use maskformatter. ensure value never entered wrong.
new jformattedtextfield(createformatter("####-##-##")); private static maskformatter createformatter(string s) { maskformatter formatter = null; try { formatter = new maskformatter(s); formatter.setplaceholdercharacter('0'); } catch (java.text.parseexception exc) { system.err.println("formatter bad: " + exc.getmessage()); system.exit(-1); } return formatter; }
Comments
Post a Comment