Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在插入或删除数据时立即刷新 JTable,我在论坛上遇到了问题,但解决方案对他们的示例过于特殊,是否有一种通用方法如何在同一页面上的任何事件发生时刷新 JTable?特别是当事件更改表模型所依赖的数据时..
应直接对 TableModel 进行更新。然后模型将通知表格,以便表格可以重新绘制自己。
如果您使用的是自定义 TableModel,那么您有责任确保在更改 TableModel 时调用从 AbstractTableModel 继承的正确 fireXXX() 方法。
使用 DefualtTableModel 是一种简单的开始方式,因为它会为您完成所有这些工作。