Note that there are some explanatory texts on larger screens.

plurals
  1. POJCalendar set specific date colors
    text
    copied!<p>I am using the code from the solution to set the colors of a specific date in toedter's JCalendar at <a href="https://stackoverflow.com/questions/16234388/add-specific-background-colors-to-jdaychooser-dates">Add specific background colors to JDaychooser Dates</a>. The problem with this solution is that it sets a different day for each month because the first day for each month is different. </p> <p>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. </p> <p>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.</p> <p><img src="https://i.stack.imgur.com/gyTuT.png" alt="enter image description here"></p> <p>Heres my code:</p> <pre><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 &lt; events.size(); i++) { //selected month and year on JCalendar if(month == events.get(i).getMonth() &amp;&amp; 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); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload