Is it possible to add a DateTimePicker to a JTable Cell.A particular column should be updated with date and time..Is it possible to add such a component to a JTable
6 Answers
The LGoodDatePicker library includes three TableEditor classes. These classes allow the programmer to add a DatePicker, a TimePicker, or a DateTimePicker, to the cells of a Swing JTable (or to a SwingX JXTable).
Fair disclosure: I'm the primary developer.
The picker classes can also be added to normal swing panels or other swing containers.
Here is an example of how to add a DateTimePicker to your JTable:
// Create a table.
JTable table = new JTable(new DemoTableModel());
// Add the DateTimeTableEditor as the default editor and renderer for
// the LocalDateTime data type.
table.setDefaultEditor(LocalDateTime.class, new DateTimeTableEditor());
table.setDefaultRenderer(LocalDateTime.class, new DateTimeTableEditor());
// Explicitly set the default editor and renderer for column index 0.
TableColumn column = table.getColumnModel().getColumn(0);
column.setCellEditor(table.getDefaultEditor(LocalDateTime.class));
column.setCellRenderer(table.getDefaultRenderer(LocalDateTime.class));
I've pasted screenshot below of the table editor demo, the picker components, and the full demo. Note that the library includes a separate demo for the table editors. It's in the Repository under this folder: "LGoodDatePicker/Project/src/main/java/com/github/lgooddatepicker/demo/TableEditorsDemo.java".
The library can be installed into your Java project from the project Release Page.
The project home page is on Github at:
https://github.com/LGoodDatePicker/LGoodDatePicker .

- 941
- 11
- 14
Yes it is. See this Swing Tutorial Track: http://download.oracle.com/javase/tutorial/uiswing/components/table.html#combobox

- 77,657
- 34
- 181
- 348
-
-300 because the Tutorial does not mention any Editor for Date and Time; just a Renderer for a Date. – bobndrew Aug 25 '10 at 13:44
-
2+1, yes the tutorial doesn't give a specific example of a date editor, but it does show how to use a color chooser as an editor. So the concept will be the same. All the OP has to do is find a Date editor that they like to use. There are many date editors floating around on the web. – camickr Aug 25 '10 at 14:37
Try to use the FLib-JCalendar component as an CellEditor in a JTable.
(and post the working example here if you made it work)

- 395
- 10
- 32
-
1Can you elaborate? It's not clear if you found the component difficult to use. – trashgod Aug 25 '10 at 14:23
Simply use this code to set DatePicker in column 0:
TableColumn dateColumn = YOURTABLE.getColumnModel().getColumn(0);
dateColumn.setCellEditor(new DatePickerCellEditor());

- 63
- 7
By using the premise of Jens link and applying that logic with the below link, you can add a date time picker into a JTable, just be careful, combining JCheckbox, JCombobox and the date time picker into a JTable the focus get a little messy, but i believe it can be solved with a focus listener, it will just take some time t implement.
I am currontly working on such a Table render-er with will incorperate it all, i will post it online when im done.

- 1
- 1

- 453
- 3
- 8