Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date time picker inside JTable

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

like image 532
Harish Avatar asked Dec 12 '25 04:12

Harish


2 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 .

. Table Editors Demo screenshot

Date and TimePicker screenshots

Full Demo screenshot

like image 96
BlakeTNC Avatar answered Dec 14 '25 18:12

BlakeTNC


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

like image 39
Jens Schauder Avatar answered Dec 14 '25 19:12

Jens Schauder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!