JTable + TableCellEditor:数据缓冲区更改
我的问题针对可编辑的 JTable(使用 TableCellEditor)。
某些工具(如 SQLDeveloper)允许用户编辑多条记录、创建新记录或删除现有记录。该表显示了修改的记录,但修改仅限于本地,直到用户单击“保存”按钮(或在 SQLDeveloper 中单击“提交”)。用户还可以恢复所有更改。
在带有 JTable 的 Swing 应用程序中实现此行为的最佳方法是什么?
我不认为像 SQLDeveloper 这样的工具会创建表中列出的记录的副本。我的第一个想法是创建一个 TableModel 来包装另一个 TableModel(这允许我使用 TableModel 的任意实现)并仅存储修改后的单元格的值。当行数没有改变时,这工作得很好。但是如何处理插入或删除行呢?
预先感谢您的任何提示。
马库斯
my questions targets at editable JTables (using TableCellEditor).
Some tools (like SQLDeveloper) allow the user to edit multiple records, create new one or delete existing records. The table shows the modified records, but the modifications are local only, until the user clicks a "save" button (or "commit" in case of SQLDeveloper). The user can also revert all his changes.
What is the best way to implement this behaviour in a Swing application with a JTable?
I don't think, that a tool like SQLDeveloper creates a copy of records listed in the table. My first idea was to create a TableModel that wraps another TableModels (this allows me to use an arbitrary implementation of TableModel) and stores only the values of the modified cells. This works fine, when the number of rows does not change. But how to handle inserting or removing rows?
Thanks in advance for any hints.
Markus
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的
TableModel
中,您可以向父TableModel
注册一个TableModelListener
,并在您的模型中相应地处理插入或删除事件。Inside your
TableModel
your can register aTableModelListener
with the parentTableModel
and process the events for insertion or deletion accordingly also within your model.