TableRowSorter 和 RowFilter - 搜索可见和渲染的列
我正在使用 TableRowSorter 和 RowFilter 来过滤 JTable 中的数据。我在使用它时遇到了两个问题。
1)我的表有可见列和隐藏列。我想避免搜索隐藏的列。有办法做到这一点吗?
2)我使用自定义单元格渲染器来渲染单元格中的值。我想搜索渲染值而不是实际值。例如,当状态列的实际值为“true”时,呈现的值为“enabled”。当启用搜索文本时,我应该能够看到数据。
你能帮忙吗?
多谢
I am using TableRowSorter and RowFilter for filtering data in a JTable. I have come across 2 issues while using it.
1) My table has visible and hidden columns. I would like to avoid searching hidden columns. Is there a way to do that?
2) I am using custom cell renderers to render the values in the cell. I would like to search the rendered value instead of the actual value. For example when actual value is "true" for status column, the rendered value is "enabled". I should be able to see data when search text is enabled.
Could you please help?
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1) 阅读 JTable API 并点击有关“如何使用表”的 Swing 教程的链接。过滤器示例显示了如何对特定列进行过滤
2) 我想您必须创建一个自定义过滤器。在过滤器内部,您需要使用 TableModel 中的值调用prepareRenderer(...) 方法。我从来没有这样做过,所以我无法举例。
1) Read the JTable API and follow the link to the Swing tutorial on "How to Use Tables". The filter example shows how to filter on a specific column
2) I guess you would have to create a custom filter. Inside the filter you would need to invoke the prepareRenderer(...) method using the value in the TableModel. I've never done this so I'm can't give an example.