How to set specific column settings in JTable?

Posted by HansDampf on Stack Overflow See other posts from Stack Overflow or by HansDampf
Published on 2010-05-05T18:17:23Z Indexed on 2010/05/05 18:28 UTC
Read the original article Hit count: 304

Filed under:
|
|

How can I make my JTable show specific stuff for each column?

Can I use an Object for more than one column? I want to have a column showing the date (dd.mm.yyyy) and another to show the time (hh:mm) but as I have it now it only shows the String representation of the Date object as a whole.

public class AppointmentTableModel extends AbstractTableModel {
    ...
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        return appointments.get(rowIndex).getByColumn(columnIndex);
    }
}

public class Appointment {
    ...
    public Object getByColumn(int columnIndex) {
        switch (columnIndex) {
            case 0: return date;
            case 1: return date;
            case 2: return sample;
            case 3: return sample;
            case 4: return history;
            case 5: return comment;
        }
        return null;
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about swing