Java Swing: How to add a CellRenderer for displaying a Date?

Posted by HansDampf on Stack Overflow See other posts from Stack Overflow or by HansDampf
Published on 2010-05-05T23:48:13Z Indexed on 2010/05/05 23:58 UTC
Read the original article Hit count: 141

Filed under:
|
|

I have a Table:

public class AppointmentTableModel extends AbstractTableModel {
    private int columns;
    private int rows;
    ArrayList<Appointment> appointments;...

So each row of the table contains one Appointment.

public class Appointment {

    private Date date;
    private Sample sample;
    private String comment;
    private ArrayList<Action> history;

    public Appointment(Date date, Sample sample, String comment) {
        this.date = date;
        this.sample = sample;
        this.comment = comment;
        this.history = new ArrayList<Action>();
    }

    public Object getByColumn(int columnIndex) {
        switch (columnIndex) {
        case 0: return date;//Date: dd:mm:yyyy

        case 1: return date;//Time mm:hh

        case 2: return sample;//sample.getID() int (sampleID)

        case 3: return sample;//sample.getNumber string (telephone number)

        case 4: return sample;//sample.getName string (name of the person)

        case 5: return history;//newst element in history as a string

        case 6: return comment;//comment as string


        }
        return null;

I added in comments what this one is going to mean. How would I create CellRenderers to display it like this.

   table.getColumnModel().getColumn(1).setCellRenderer(new DateRenderer());

I also want to add the whole row to be painted in red when the date is later then the current date. And then another column that holds a JButton to open up another screen with the corresponding Appointment as parameter.

© Stack Overflow or respective owner

Related posts about java

Related posts about swing