Skip to main content

Formatting a date in a JXTable

Please note these forums are being decommissioned and use the new and improved forums at
No replies
Joined: 2006-07-26

I've recently started using a JXTable to visualize some date and highlighting some rows using highlighers. This works great.
However, I have one date column that I would like to format using a specific pattern. This should be a simple task but I've been searching for hours for a sollution but can't find any.
I've basically tried two approaches: using CellRenderers and using highlighters, but none seem to work:
Cellrenderer approach:
logTable.setDefaultRenderer(Date.class, new DefaultTableRenderer(new StringValue() {

public String getString(Object value) {
if (value == null) return null;
return DATE_FORMAT.format((Date) value);
Highlighter approach:
logTable.addHighlighter(new AbstractHighlighter() {

protected Component doHighlight(Component renderer, ComponentAdapter componentAdapter) {
Object value = componentAdapter.getValue();
if (value != null && value instanceof Date) {
if (renderer instanceof JLabel) {
JLabel label = (JLabel) renderer;
label.setText(DATE_FORMAT.format((Date) value));
return renderer;
BTW My tablemodel is identifying the date collumn as beeing of type Date, but it seems the getColumnClass method on the model is never called.
I would really appreciate any pointers on how to implement this.
Best regards