如何用向量刷新JTable

发布于 2024-10-27 15:06:16 字数 693 浏览 0 评论 0原文

我已经被这个问题难住有一段时间了。我知道您使用表模型用新值刷新实际表,但我似乎无法让它工作。我已在表单中添加了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你丑哭了我 2024-11-03 15:06:16

如果您有选择并且它适合您的需求,我建议您查看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.

浅笑轻吟梦一曲 2024-11-03 15:06:16

我相信您需要手动将表添加为表 TableModel 的侦听器。

I believe you need to manually add your Table as Listener of table TableModel.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文