Skip to main content

Week number in JXMonthView

No replies
braendi
Offline
Joined: 2010-06-24

Hi

Given this code:

import javax.swing.JFrame;

import org.jdesktop.swingx.JXDatePicker;

public class JXDatePickerExpample {

public static void main(String[] args) {

// Locale.setDefault(new Locale("de", "CH"));
Locale.setDefault(new Locale("en", "CH"));
createAndShowGui();
}

private static JXDatePicker createDatePicker() {
DateFormat timeFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
JXDatePicker txPicker = new JXDatePicker();
txPicker.getMonthView().getCalendar().setMinimalDaysInFirstWeek(4);
txPicker.getMonthView().setShowingWeekNumber(true);
txPicker.setFormats(timeFormat);
txPicker.getMonthView().setShowingWeekNumber(true);
return txPicker;
}

public static void createAndShowGui() {
JFrame frame = new JFrame("JXDatePickerWeekProblem");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().add(createDatePicker());

frame.pack();
frame.setVisible(true);
}
}

JXDatePicker shows different week numbers, depending on the Locale, I set in the main method. That alone doesn't surprise me too much. Now, if I choose de_CH, week starts on Monday, and January 1-3 belong to week 53 of 2009 and week 1/2010 starts with January, 4. That's quite, what I'm expecting. But... if I choose en_CH, week starts on Sunday, and January 1-2 belong to week 1/2010.

Seems, that setMinimalDaysInFirstWeek(4) is beeing ignored, if I set the language to English. And anyway, shouldn't all that rather depend on the country instead of the language?

Stefan

BTW: How do I format my code here in this forum?