JTable 行过滤器更新

发布于 2024-08-26 20:20:16 字数 239 浏览 5 评论 0原文

有没有办法告诉 JTable 的行过滤器应该更新自身以显示过滤后的数据?我目前正在 AbstractTableModel 中使用 fireTableDataChanged 方法,但表的基础数据实际上并未更改,因此这看起来可能很浪费。我的过滤器的工作方式是检查表中的数据是否在其他列表中,并且仅在该列表中时才显示它。因此其他列表发生了变化,我需要告诉过滤器自行刷新。 fireTableDataChanged 是执行此操作的正确方法吗?

谢谢, 杰夫

Is there a way to tell a JTable's row filter that it should update itself to display the filtered data? I'm currently using the fireTableDataChanged method in the AbstractTableModel but the underlying data for the table isn't actually changing, so this seems like it might be wasteful. The way my filter works is to check if data in the table is in some other list and only display it if it is in that list. So that other list changed and I need to tell the filter to refresh itself. Is fireTableDataChanged the correct way to do this?

thanks,
Jeff

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

多情出卖 2024-09-02 20:20:16

fireTableDataChanged 是正确的方法。

我会将“其他列表”视为您数据的一部分。这意味着它应该是您的表模型的一部分。因此,每当模型发生变化时,都应该调用 fireTableDataChanged。这样就可以解决问题了。

如果您无法使其成为模型的一部分,那么它至少应该在发生更改时通知模型,然后模型将调用 fireTableDataChanged。对于通知,您可以使用标准侦听器方法,或者如果您更喜欢全局方法事件总线框架可以提供帮助。

fireTableDataChanged IS a correct way to do it.

I would consider the "other list" a part of your data. That means it should be a part of your table model. So whenever it changes the model should call fireTableDataChanged. This will do the trick.

If you cannot make it a part of your model it at least should notify the model when change happened and then model will call fireTableDataChanged. For notification you can use standard listeners approach or if you prefer global approach Event Bus framework can be of help .

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