为什么我的 TableRowFilter 无法过滤?
我正在尝试使用 TableRowFilter 过滤 JTable 。它在一个简单的例子中对我有用,但我似乎无法让它在真实的事情上工作。过滤器被调用,日志被打印 - 但我仍然看到行。有什么想法吗?
public class TopicTable extends JTable {
...
public TopicTable(ITopic topic) {
super();
TopicTableDataModel model = new TopicTableDataModel(topic);
setModel(model);
setRowSorter(generateTableRowSorter(model));
setFillsViewportHeight(true);
setColumnRenderers();
}
private TableRowSorter<TableModel> generateTableRowSorter(TableModel model) {
RowFilter<Object, Object> classFilter = new RowFilter<Object, Object>() {
@Override
public boolean include(javax.swing.RowFilter.Entry<? extends Object, ? extends Object> entry) {
log.debug("Filtering? " + entry.getValue(1));
return false;
}
};
TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
sorter.setRowFilter(classFilter);
return sorter;
}
...
}
I'm trying to filter a JTable using a TableRowFilter . It works for me on a simple example , but I can't seem to get it to work on the real thing. The filter is called , the logs are printed - but I staill see the rows . Any ideas?
public class TopicTable extends JTable {
...
public TopicTable(ITopic topic) {
super();
TopicTableDataModel model = new TopicTableDataModel(topic);
setModel(model);
setRowSorter(generateTableRowSorter(model));
setFillsViewportHeight(true);
setColumnRenderers();
}
private TableRowSorter<TableModel> generateTableRowSorter(TableModel model) {
RowFilter<Object, Object> classFilter = new RowFilter<Object, Object>() {
@Override
public boolean include(javax.swing.RowFilter.Entry<? extends Object, ? extends Object> entry) {
log.debug("Filtering? " + entry.getValue(1));
return false;
}
};
TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
sorter.setRowFilter(classFilter);
return sorter;
}
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如所有愚蠢的错误一样,这就是其中之一。在使用此表的另一个类中,我使用了 table.setAutoCreateRowSorter(true) - 所以即使认为原始排序器仍然运行,默认排序器也运行,然后什么也没有发生。
As all stupid bugs go - this was one of them . In another class that use this table , I used table.setAutoCreateRowSorter(true) - so even thought the original sorter still ran , the default one also did , and then nothing happened.