Menu

Problem or Bug DateComboBox

Help
2007-02-01
2013-03-27
  • klipper0815

    klipper0815 - 2007-02-01

    The DateComboBox - Popup shows a wrong day of the current date. It means for example the 01.02.2007 was displayed as Friday not as Thursday. I've change one Line (Linenumber: 611) in DateComboBox.java.

    File: DateComboBox.java (orginal)
    -----------------------------------------------------------
    ...
    setupCalendar = (Calendar) calendar.clone();
          setupCalendar.set(Calendar.DAY_OF_MONTH, 1);
          int first = setupCalendar.get(Calendar.DAY_OF_WEEK);
          for (int i = 0; i < (first - 1); i++) {
            days.add(new JLabel(""));
          }
    ...
    ------------------------------------------------------------

    I've change the begin of the loopcount from 0 to 1.

    File: DateComboBox.java (change)
    -----------------------------------------------------------
    ...

    setupCalendar = (Calendar) calendar.clone();
          setupCalendar.set(Calendar.DAY_OF_MONTH, 1);
          int first = setupCalendar.get(Calendar.DAY_OF_WEEK);
          for (int i = 1; i < (first - 1); i++) {
            days.add(new JLabel(""));
          }
    ...
    ------------------------------------------------------------

    java version: 1.5.0_06

    Is this a known Problem?
    Bye

     
    • Oliver Möller

      Oliver Möller - 2007-11-29

      I've noticed this issue, too. However, this bug is dependent on the language setting. If java is started with "-Duser.language=en" everything works fine, but e.g. with "-Duser.language=de" the mentioned problem of false weekdays occurs.

      The reason is the behaviour of Calendar.getFirstDayOfWeek(): "Gets what the first day of the week is; e.g., Sunday in US, Monday in France.". Thus the solution must be more general.

      I've also added localized working day names as only English texts were shown before. The German weekday text abbreviations have a length of only 2 letters which does not comply with the layout (month and arrows are too near to each other), so I always try to use at least 3 weekday characters.

      Here's my new code for DateComboBox.updatePopup():

        Calendar setupCalendar = (Calendar) calendar.clone();
        setupCalendar.set(Calendar.DAY_OF_WEEK, setupCalendar.getFirstDayOfWeek());
        int firstDayOfWeek = setupCalendar.getFirstDayOfWeek();
        SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE");

        for (int i = 0; i < 7; i++) {
          JLabel label = new JLabel();
          label.setHorizontalAlignment(JLabel.CENTER);
          label.setForeground(foreground);
          String dateText = dateFormat.format(setupCalendar.getTime());

          if (dateText.length() > 3) {
            dateText = dateText.substring(0, 3);
          }

          label.setText(dateText);
          days.add(label);
          setupCalendar.roll(Calendar.DAY_OF_WEEK, true);
        }

        setupCalendar = (Calendar) calendar.clone();
        setupCalendar.set(Calendar.DAY_OF_MONTH, 1);
        int first = setupCalendar.get(Calendar.DAY_OF_WEEK);
        int skipDays = first - firstDayOfWeek;

        if (skipDays < 0) {
          skipDays += 7;
        }

        for (int i = 0; i < skipDays; i++) {
          days.add(new JLabel(""));
        }

       

Log in to post a comment.