JTable 行过滤器更新
有没有办法告诉 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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 .