Date time picker inside JTable
Solution 1
Yes it is. See this Swing Tutorial Track: http://download.oracle.com/javase/tutorial/uiswing/components/table.html#combobox
Solution 2
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 .
Solution 3
Yes, but you'll need to implement both TableCellRenderer
and TableCellEditor
. As suggested by @Jens Schauder, the tutorial may be helpful. You might also look at this tutorial based example using JCheckBox
.
Solution 4
Try to use the FLib-JCalendar component as an CellEditor in a JTable.
(and post the working example here if you made it work)
Solution 5
Simply use this code to set DatePicker in column 0:
TableColumn dateColumn = YOURTABLE.getColumnModel().getColumn(0);
dateColumn.setCellEditor(new DatePickerCellEditor());
Harish
Updated on June 09, 2022Comments
-
Harish about 2 years
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