Search code examples
javaswingswingxjcalendar

JXDatePicker questions (part 2)


I want to ask some questions about jxdatepicker:

(1) I write the following code to change the date format:

public test(){
    SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd");
    jxDatePicker1.setFormats(dateFormat);
}

When I run my gui, the datepicker is show today date (2015-03-03) but when I click yesterday date, it goes to another date (2015-12-28) not the yesterday date. What happened to my code?

(2) How to change the header title color?

(3) How to change the color of the selected date?

enter image description here


Solution

    1. The date format is wrong, it should be yyyy-MM-dd
    2. Use JXDatePicker#getMonthView#setMonthStringBackground
    3. Use JXDatePicker#getMonthView#setSelectionBackground. If you want to change the color use to "highlight" today, you can also use JXDatePicker#getMonthView#setTodayBackground - but it only colors the border of the box when today is not highlighted...

    enter image description here