I am using the code from the solution to set the colors of a specific date in toedter's JCalendar at Add specific background colors to JDaychooser Dates. The problem with this solution is that it sets a different day for each month because the first day for each month is different.
in my example i have added 4th of May and 4th of September in the events arraylist.+9 from the day works for May but in September it will select 7 instead because the first day of the month starts at +6.
I'm wondering if there is a way to get the start date for the month but i can't seem to find a method that does this in the API documentation.
Heres my code:
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 of events
for(int i = 0; i < events.size(); i++)
{
//selected month and year on JCalendar
if(month == events.get(i).getMonth() && year == events.get(i).getYear())
{
//this value will differ from each month due to first days of each month
component[ events.get(i).getDay() + 9 ].setBackground(Color.blue);
}
}