是否可以将 DateTimePicker 添加到 JTable 单元格。特定列应使用日期和时间更新。是否可以将此类组件添加到 JTable
最佳答案
LGoodDatePicker库包括三个 TableEditor 类。这些类允许程序员将 DatePicker、TimePicker 或 DateTimePicker 添加到 Swing JTable(或 SwingX JXTable)的单元格中。
公平披露:我是主要开发者。
拾取器类也可以添加到普通 Swing 面板或其他 Swing 容器中。
这是一个如何将 DateTimePicker 添加到 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));
我在下面粘贴了表编辑器演示、选择器组件和完整演示的屏幕截图。请注意,该库包含一个单独的表编辑器演示。它在 Repository 中在此文件夹下:“LGoodDatePicker/Project/src/main/java/com/github/lgooddatepicker/demo/TableEditorsDemo.java”。
库可以从项目 Release Page 安装到您的 Java 项目中.
项目主页在 Github 上:
https://github.com/LGoodDatePicker/LGoodDatePicker .
关于java - JTable 中的日期时间选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3562799/