Search code examples
javaswingdate-formatsimpledateformatjformattedtextfield

How check the correctness of the month only after the second digit?


I need JFormattedTextField which will format date ("dd.MM.yy"). Code:

SimpleDateFormat format= new SimpleDateFormat("dd.MM.yy");
DateFormatter formatter = new DateFormatter(format);
format.setLenient(false);
formatter.setAllowsInvalid(false);
formatter.setOverwriteMode(true);
JForemattedTextField inputText = new JFormattedTextField(formatter);
inputText.setValue(new Date());

The problem is: if the date is "11/06/12" for example and if I try to input 12 on month I can't do it because when I type 1 it understands the month as 16 and doesn't give me to input the next digit. I need that when I type for example 12 on month position then the JFormattedTextField will check the correctness of the month only after I typed the second digit, and if it is incorrect the month will return back to previous value. How can I solve this?


Solution