如何用向量刷新JTable
我已经被这个问题难住有一段时间了。我知道您使用表模型用新值刷新实际表,但我似乎无法让它工作。我已在表单中添加了一个 tablemodellistener 并具有一个 tableChanged 方法。但是,我似乎无法弄清楚为什么当我插入表时没有调用 tableChanged 方法。
public void tableChanged(TableModelEvent e) {
int row = e.getFirstRow();
int column = e.getColumn();
DefaultTableModel model = (DefaultTableModel)e.getSource();
// String columnName = model.getColumnName(column);
//Object data_1 = model.getValueAt(row, column);
//model.fireTableCellUpdated(row, column);
//model.fireTableDataChanged();
//customerTable.repaint();
}
如果单击表单上的刷新按钮,我可以完全重建表吗?这可能吗?如果没有,我是否必须从刷新按钮的操作执行方法中调用 tableChanged 方法才能触发它?我已经在这个问题上坚持了一段时间了,我只是想弄清楚这一点,以利于学习。
I have been stumped with this for quite some time now. I understand you use the table model to refresh the actual table with the new values however I cannot seem to get this to work. I have added a tablemodellistener to my form and have a tableChanged method. However, I cannot seem to figure out why the tableChanged method isn't getting called when I insert into a the table.
public void tableChanged(TableModelEvent e) {
int row = e.getFirstRow();
int column = e.getColumn();
DefaultTableModel model = (DefaultTableModel)e.getSource();
// String columnName = model.getColumnName(column);
//Object data_1 = model.getValueAt(row, column);
//model.fireTableCellUpdated(row, column);
//model.fireTableDataChanged();
//customerTable.repaint();
}
Could I completely rebuild the table if I click the refresh button on my form? Would that at all be possible? If not, do I have to call my tableChanged method from my refresh button's action performed method in order for it to trigger? I've been stuck on this for quite some time now and I would just like to get this figured out for the benefit of learning.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有选择并且它适合您的需求,我建议您查看GlazedLists。然后您就不必担心更新表模型——这一切都为您处理好了。
这里跳转到GlazedLists 教程的相关部分 。
If you have the option and it fits your needs, I'd reccomend taking a look at GlazedLists. Then you won't have to worry about updating your table models--it's all handled for you.
Here's a jump to a relevant part of the GlazedLists tutorial.
我相信您需要手动将表添加为表 TableModel 的侦听器。
I believe you need to manually add your Table as Listener of table TableModel.