我正在编写一个程序,该程序将两个过滤器应用于JTable
,然后将结果提供给我。
public void rowF(String one, String two){
RowFilter<DefaultTableModel, Object> rf = null;
List<RowFilter<Object,Object>> filters = new ArrayList<RowFilter<Object,Object>>(2);
filters.add(RowFilter.regexFilter(one, 0));
filters.add(RowFilter.regexFilter(two, 1));
rf = RowFilter.andFilter(filters);
}
据我所知,这是这样做的方法。但是问题是当我调用它时,它没有显示结果。
这是按钮的代码-搜索。
String quer = jtxtsearch.getText();
String query = jtxtsearch2.getText();
String search = (String)jcbox.getSelectedItem();
String perch = (String)jcbox2.getSelectedItem();
if (search.equals("ID")){
if (perch.equals("Date")){
rowF(quer,query);
}
}
答案 0 :(得分:0)
这是为我工作的人:
public void builtxsize (String one,String two){
TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(jtablestate.getModel());
jtablestate.setRowSorter(sorter);
RowFilter<TableModel, Object> firstFiler = null;
RowFilter<TableModel, Object> secondFilter = null;
List<RowFilter<TableModel,Object>> filters = new
ArrayList<RowFilter<TableModel,Object>>();
RowFilter<TableModel, Object> compoundRowFilter = null;
try {
firstFiler = RowFilter.regexFilter(one, indexofcolumn);
secondFilter = RowFilter.regexFilter(two, indexofcolumn);
filters.add(firstFiler);
filters.add(secondFilter);
compoundRowFilter = RowFilter.andFilter(filters);
} catch (java.util.regex.PatternSyntaxException e) {
return;
}
sorter.setRowFilter(compoundRowFilter);
}
可以通过以下方式进行调用:
String one = jtxt.getText();
String two = jtxt2.getText();
builtxsize(one,two);