在以下代码中,即使我将所需值设置为 CASEID , ANY 和 NUM ,JTable也会删除所有内容。我无法弄清楚我做错了什么。
public void filter(FilterArgs fa){
TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>();
mTable.setRowSorter(sorter);
ArrayList<RowFilter<Object,Object>> filters = new ArrayList<RowFilter<Object,Object>>(3);
TableModel model = mModel;
System.out.println(fa.getCaseID());
System.out.println(fa.getAlarmID());
System.out.println(fa.getState());
System.out.println(fa.getNumAlarms());
if(!fa.getCaseID().equals("*CASEID*")){
filters.add(RowFilter.regexFilter(".*"+fa.getCaseID()+".*",0));//filter first column
}
else{filters.add(RowFilter.regexFilter(".*",0));}//don't filter first column
if(!fa.getState().equals("*ANY*")){
filters.add(RowFilter.regexFilter(".*"+fa.getState()+".*",4));//filter fifth column
}
else{filters.add(RowFilter.regexFilter(".*",4));}
if(!fa.getNumAlarms().equals("*NUM*")){
int num = Integer.parseInt(fa.getNumAlarms());
if(fa.getOperatorNumAlarms().equals("<")){
filters.add(RowFilter.numberFilter(ComparisonType.BEFORE,num,7));
}
if(fa.getOperatorNumAlarms().equals("=")){
filters.add(RowFilter.numberFilter(ComparisonType.EQUAL,num,7));
}
if(fa.getOperatorNumAlarms().equals(">")){
filters.add(RowFilter.numberFilter(ComparisonType.AFTER,num,7));
}
}
else{filters.add(RowFilter.regexFilter(".*",7));}
RowFilter<Object,Object> filter = RowFilter.andFilter(filters);
sorter.setRowFilter(filter);
}