Mark JCalendar when there is an event on the day [closed]

0

In my Java Desktop application, I'm thinking of adding a JCalendar to easily inform on what day there are events that will be written to a database.

My question is whether it is possible to make a markup or change of color in the calendar of the month.

    
asked by anonymous 16.09.2015 / 15:05

1 answer

1

I think you can use setBackground, here is an example:

Calendar cal = Calendar.getInstance();
cal.setTime(calendar.getDate());
int day = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);

JPanel jpanel = calendar.getDayChooser().getDayPanel();
Component component[] = jpanel.getComponents();

//arraylist dos eventos
for(int i = 0; i < events.size(); i++)
{
    //mês e ano selecionado em JCalendar
    if(month == events.get(i).getMonth() && year == events.get(i).getYear())
    {
         // Calcular o deslocamento do primeiro dia do mês
         cal.set(Calendar.DAY_OF_MONTH,1);
         int offset = cal.get(Calendar.DAY_OF_WEEK) - 1;

        //Este valor será diferente de cada mês, devido aos primeiros dias de cada mês
         component[ events.get(i).getDay() + offset ].setBackground(Color.blue); 
    }
}
    
16.09.2015 / 15:51