java - JFormattedTextField set value and text null after inputting wrong format -


i'm working java application jformattedtextfield. have problems that:

  1. how set jformattedtextfield can accept "/" , "-"

  2. i want set jformattedtextfield value , text null or "" after entering wrong format.

example:

2.1.jformattedtextfield ftf .... format ("yyyy-mm-dd")

enter image description here

2.2. input right format: 1990-5-6

enter image description here

2.3. leave ftf

enter image description here

2.4. focus ftf , input wrong format: 5-6-1990

enter image description here

2.5. leave ftf recognize wrong format return else

enter image description here

but want must null or empty.

enter image description here

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

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -