javaswingjcalendar

Disable dates JDates Chooser


I'm newbie and I want to disable dates like shown in this example but in a JDateChooser button. Here is my code and hope you guys can help me.

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

RangeEvaluator evaluator = new RangeEvaluator();
evaluator.setStartDate(dateFormat.parse("2013-09-14"));
evaluator.setEndDate(dateFormat.parse("2013-09-23"));


JDateChooser calendar = new JDateChooser();
calendar.getCalendar.(evaluator);
// evaluator must be added to a JDayChooser object 

calendar.setSize(180, 25); 
calendar.setLocation(140, 640);
calendar.setVisible(true);
calendar.updateUI();
this.add(calendar);

Solution

  • Let's start with your question: How to add an IDateEvaluator to a JDateChooser? This is a really easy-to-solve problem but you must know the API first:

    So you basically need to get the reference to the JDayChooser component and add the date evaluator like this:

    RangeEvaluator evaluator = new RangeEvaluator();
    ...
    JDateChooser dataChooser = new JDateChooser();
    dateChooser.getJCalendar().getDayChooser().addDateEvaluator(evaluator);
    

    Other comments