Disable multiple date ranges jDateChooser

Based on your update there are two things that happen here.

First is a little mistake when you instatiate your SimpleDateFormat:

SimpleDateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy");

In this pattern “mm” refers to minutes not months. It should be:

SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");

Second problem is IMHO a bug since day chooser seems to not apply filters until a new date is set or it has to be repainted because of month/year change. You can test it changing month to August and then back to September: dates from 9/11 to 9/15 will be disabled. To solve this inconvenient behavior just set current date explicitely like this:

JCalendar calendar = new JCalendar();
calendar.getDayChooser().addDateEvaluator(evaluator);
calendar.setDate(Calendar.getInstance().getTime());

Side note: while this library is very very useful it has a couple of bug/design issues so don’t hesitate to ask for help.

Leave a Comment