为什么我的 TableRowFilter 无法过滤?

发布于 2024-10-11 06:23:22 字数 1001 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

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

发布评论

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

评论(1

南街女流氓 2024-10-18 06:23:22

正如所有愚蠢的错误一样,这就是其中之一。在使用此表的另一个类中,我使用了 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.

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