0

I'm trying to create a calendar to display and modify a schedule. To do this I have to change the color of some dates in that calendar. I have followed examples that created a RangeEvaluator and managed to highlight the dates. The problem is that if I click that date (and I need to in order to modify it from busy to free for exemple) its color goes back to normal. Here is my code:

RangeEvaluator evaluator = new RangeEvaluator();
//get dates from DB:
    Vector<Date> vd=SA.getCalendrier(transport);
    evaluator.setVd(vd);
    calendar.getDayChooser().addDateEvaluator(evaluator);
Community
  • 1
  • 1
Hodyr
  • 53
  • 7

1 Answers1

1

As shown here, your IDateEvaluator is probably returning specific foreground and background colors to highlight the dates. Note that the foreground color remains set when you click a highlighted date button. In contrast, as mentioned here, the background color belongs to the chosen Look & Feel. I'd rely on foreground color and tooltip; I'd consider background color highlighting optional.

As a workaround, shown here, you can set a bound property in your PropertyChangeListener to reconfigure the buttons, but the selected button will still be rendered according to the Look & Feel. Select a button that's not highlighted to see the effect.

JCalendar jc = new JCalendar();
jc.getDayChooser().addDateEvaluator(evaluator);
jc.setDate(Calendar.getInstance().getTime());
jc.addPropertyChangeListener("calendar", new PropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent e) {
        jc.setDate(Calendar.getInstance().getTime());
        …
    }
});

More generally, note that JCalendar is a date chooser, not a day planner.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045