如何在JTable中搜索特定字符串,而不是子字符串?

时间:2014-10-09 12:04:48

标签: java search filter jtable

我已经搜索了JTable。此代码过滤两列。一列有两个相似的单词,因此过滤器不起作用。这是我的代码:

    RowFilter<DefaultTableModel, Object> firstFiler = null;
    RowFilter<DefaultTableModel, Object> secondFilter = null;
    List<RowFilter<DefaultTableModel,Object>> filters = new      ArrayList<RowFilter<DefaultTableModel,Object>>();
    RowFilter<DefaultTableModel, Object> compoundRowFilter = null;

    try {
        secondFilter = RowFilter.regexFilter(this.filter, 12);
        firstFiler = RowFilter.regexFilter("AKTIVAN", 8);
        filters.add(firstFiler);
        filters.add(secondFilter);
        compoundRowFilter = RowFilter.andFilter(filters); 
    } catch (java.util.regex.PatternSyntaxException e) {
        return;
    }   

    final TableRowSorter<DefaultTableModel> sorter = new TableRowSorter<DefaultTableModel>((DefaultTableModel) printTable.getModel());

    sorter.setRowFilter(compoundRowFilter);
    printTable.setRowSorter(sorter);

在第8栏中,我有“NEAKTIVAN”,“AKTIVAN”字样。如何只搜索“AKTIVAN”?

1 个答案:

答案 0 :(得分:0)

试试这个

firstFiler = RowFilter.regexFilter("\bAKTIVAN\b", 8);

而不是

firstFiler = RowFilter.regexFilter("AKTIVAN", 8);