且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JTable 如何在插入删除或更新数据后刷新表模型.

更新时间:2023-12-03 12:45:34

如果你想通知你的 JTable 关于你的数据的变化,使用
tableModel.fireTableDataChanged()

If you want to notify your JTable about changes of your data, use
tableModel.fireTableDataChanged()

来自 文档:

通知所有侦听器表格行中的所有单元格值可能已更改.行数也可能发生了变化,JTable 应该从头开始重新绘制表格.假定表的结构(按照列的顺序)是相同的.

Notifies all listeners that all cell values in the table's rows may have changed. The number of rows may also have changed and the JTable should redraw the table from scratch. The structure of the table (as in the order of the columns) is assumed to be the same.