Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4265518

SimpleDateFormat in JTable not correct for Asian locales

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 2.0.1_build25, 1.2.0
    • client-libs
    • generic, sparc
    • solaris_2.6, solaris_7

      When using SimpleDateFormat to display a date value in a JTable in an Asian locale (e.g. zh_TW), the output is not correct. The test case provided below shows how the date looks in the table and how it looks if dumped to the screen. The screen dump is correct, the table display is not. import java.awt.*;
      import java.text.*;
      import java.util.*;
      import java.io.*;

      import com.sun.java.swing.*;
      import com.sun.java.swing.table.*;

      public class DateFormatTest {

          public DateFormatTest() {
          }

          public static void main( String args[]) {
              JFrame f = new JFrame();
              JPanel p = new JPanel();

              // Create a model of the data.
              TableModel dataModel = new AbstractTableModel() {
                  public int getColumnCount() {return 2;}
                  public int getRowCount() {return 1;}
                  public Object getValueAt(int row, int col) {
                      Object obj;
                      SimpleDateFormat fm;
                      if (col == 0)
                          fm = new SimpleDateFormat("MMM d");
                      else
                          fm = new SimpleDateFormat("HH:mm:ss");
                      obj = fm.format(new Date());
                      System.out.println(obj);
                      return(obj);
                  }
              };
              JTable table = new JTable(dataModel);
              p.add(table);

              f.getContentPane().add(p);
              f.pack();
              f.validate();
              f.show();
          }
      }

            pmilnesunw Philip Milne (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: