在Java Swing表中过滤

时间:2014-07-16 10:14:06

标签: java swing jtable rowfilter

public void newFilter() {
    RowFilter<ListTable, Object> rf = null;
    //If current expression doesn't parse, don't update.
    try {
        rf = RowFilter.regexFilter(filterText.getText(), 0);
    } catch (java.util.regex.PatternSyntaxException e) {
        return;
    }
    sorter.setRowFilter(rf);

}

我在http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#sorting使用此过滤器 但是这个过滤器似乎只能在我的表上过滤int组件(除了第一个col,所有其他都是字符串)。我只想创建一个过滤器,使任何行都保留输入的文本。我对这门语言比较陌生,非常感谢你的帮助!

http://imgur.com/vGhiILG,BAheRHx,FFl0rSS 这是3张图片

1 个答案:

答案 0 :(得分:2)

您的过滤器显式应用于第0列第0列。如图here所示,您可以通过省略indices参数来包含所有列:

rf = RowFilter.regexFilter(filterText.getText());

或者,您可以包含指定的列,例如第一至第三栏:

rf = RowFilter.regexFilter(filterText.getText(), 1, 2, 3);

可以看到组合过滤器的相关示例here

附录:在有用的评论中,@ Ordous提醒我,正确的用法取决于varargs功能,Java 5中的新功能。