Hi,
What you have highlighted above is not an item, but a cell. If you want to change the color of a cell when it is clicked, do the following:
1. Declare a private DateTime variable in your class, say, clickedDate:
private DateTime clickedDate;
2. Add a CalendarListener to the Calendar object so that you can listen to click events and perform custom drawing:
calendar.addCalendarListener(new CalendarAdapter() {
@Override
public void dateClick(ResourceDateEvent e) {
// ...
}
@Override
public void draw(DrawEvent e) {
// ...
}
});
3. In the dateClick override, assign the clickedDate variable:
@Override
public void dateClick(ResourceDateEvent e) {
clickedDate = e.getDate();
}
4. To customize the color of the clicked cell, use the draw override in the CalendarListener. First, specify that you want to custom-draw timetable cells by setting Calendar.CustomDraw to CustomDrawElements.TimetableCell:
calendar.setCustomDraw(EnumSet.of(CustomDrawElements.TimetableCell));
Then, use the following code to perform the custom drawing:
@Override
public void draw(DrawEvent e) {
if (Objects.equals(e.getDate().add(e.getStartTime()), clickedDate)) {
Rectangle bounds = new Rectangle(e.getBounds());
Brushes.LightSteelBlue.applyTo(e.getGraphics(), bounds);
e.getGraphics().fill(bounds);
new Pen(Colors.DarkSlateBlue, 0).applyTo(e.getGraphics());
bounds.width -= 1;
bounds.height -= 1;
e.getGraphics().draw(bounds);
}
}
I hope this helps.
Regards,
Meppy