2

日付 ("dd.MM.yy") をフォーマットする JFormattedTextField が必要です。コード:

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());

問題は、たとえば日付が「11/06/12」で、月に 12 を入力しようとすると、1 を入力すると月が 16 と認識されて入力できないため、入力できないことです。次の桁を入力します。たとえば、月の位置に 12 を入力すると、JFormattedTextField は 2 桁目を入力した後にのみ月の正確性をチェックし、間違っている場合は月が前の値に戻るようにする必要があります。どうすればこれを解決できますか?

4

1 に答える 1

2
于 2012-06-11T17:14:25.727 に答える