1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| public class MyDateEditor extends DefaultCellEditor {
private JFormattedTextField textField;
public MyDateEditor(String format) {
super(new JFormattedTextField(new SimpleDateFormat(format)));
textField = (JFormattedTextField) getComponent();
}
@Override
public Object getCellEditorValue() {
return textField.getValue();
}
@Override
public Component getTableCellEditorComponent(JTable table,
Object value, boolean isSelected,
int row, int column) {
super.getTableCellEditorComponent(table, value, isSelected, row, column);
textField.setValue(value);
return textField;
}
}
public class MyDateRenderer extends DefaultTableCellRenderer {
private DateFormat dateFormat;
public MyDateRenderer(String format) {
dateFormat = new SimpleDateFormat(format);
}
@Override
public void setValue(Object value) {
setText((value == null) ? "" : dateFormat.format(value));
}
} |