Search code examples
javaswingtablecelleditor

In Java, how do I set a cell Editor in two different columns for the same data type?


This is my first question here, As I am a litle noob in Java, So I apologise if this is a trivial question, But I was unable to find any sort of information about it ...

My problem is: I have a Java swing form with a Jtable. I have populated the table with a tableModel and used a tableRenderer to display a I wanted.

The table has 3 columns:

col-0 = Object

col-1 = Date (just date)

col-2 = Date (just time).

I have sucessfully set the Editor (jCalendar) for the date types, but I want column-1 to have a JCalendar (wich is ok), but on column-2, I was trying to insert a JSpinner for introducing the time.

Is there a way to have different cell editors for the samer data type (in my case is Date) ?


Solution

  • Is there a way to have different cell editors for the samer data type (in my case is Date) ?

    You add the editor to a specific column of the TableColumnModel:

    table.getColumnModel().getColumn(???).setCellEditor(???);