我已经搜索了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”?
答案 0 :(得分:0)
试试这个
firstFiler = RowFilter.regexFilter("\bAKTIVAN\b", 8);
而不是
firstFiler = RowFilter.regexFilter("AKTIVAN", 8);