-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
2.0.1_build25, 1.2.0
-
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();
}
}
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();
}
}