Disable multiple date ranges jDateChooser

前端 未结 2 796
梦如初夏
梦如初夏 2020-12-04 03:42

I want to disable multiple date ranges on a JCalendar. I\'m following these steps, but I need to know how can I add multiple date evaluators. Help me please, thanks.

2条回答
  •  醉酒成梦
    2020-12-04 04:24

    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.

提交回复
热议问题