RowFilter在java中使用jcheckboxes和jtextfield

时间:2014-05-12 15:11:49

标签: java swing jtable rowfilter

我需要帮助使RowFilter工作。我正在尝试使用下面的复选框过滤第3列。当我单击其中一个时它工作正常,但是当选中多个复选框时它不起作用。

非常感谢任何帮助。完整的解释也非常有用。提前谢谢!

private void newFilter() {
    RowFilter<DefaultTableModel, Object> rf = null;
    java.util.List<RowFilter<Object,Object>> rfs = 
            new ArrayList<RowFilter<Object,Object>>(2);

    try {

        //Filter "Full Name" using TextField
        rfs.add(RowFilter.regexFilter("(?i)" + textField.getText(), 0)); 

        /*  Filter "Employee Type" using CheckBoxes
         *  ex. If both chckbxAdmin and chckbxEmployee is checked, 
         *  Jtable will filter accordingly
         */
        rfs.add(RowFilter.regexFilter("(?i)" + sfAdmin, 2));
        rfs.add(RowFilter.regexFilter("(?i)" + sfEmployee, 2));
        rfs.add(RowFilter.regexFilter("(?i)" + sfStaff, 2));

    } catch (java.util.regex.PatternSyntaxException e) {
        e.printStackTrace();
    }

    RowFilter<Object,Object> af = RowFilter.andFilter(rfs);

    sorter.setRowFilter(af);

}

0 个答案:

没有答案