JTable row filtering based on values of two different columns
java, jtable, nested, rowfilter, swing
Solution
Use the `and` filter:
//rf = RowFilter.regexFilter(filterText.getText(), 0);
List<RowFilter<Object,Object>> filters = new ArrayList<RowFilter<Object,Object>>(2);
filters.add(RowFilter.regexFilter(filterText.getText(), 0));
filters.add(RowFilter.regexFilter(filterText.getText(), 1));
rf = RowFilter.andFilter(filters);
The above code was modified from the example found in Sorting and Filtering.
Problem
I want to implement row filtering in a JTable, based on values of two different columns: column1 = 1 column2 = 5 Here is the method that performs row-filtering based on INDEX_FIELD = 1 condition: ``` public void rowFiltering(int x) { RowFilter<ResultsModel, Integer> IDfilter = RowFilter.numberFilter( ComparisonType.EQUAL, x, column1); resultsTableSorter.setRowFilter(IDfilter); } rowFiltering(1); ``` How can I implement row filtering based on two values? Something like... ``` rowFiltering(valueColumn1, valueColumn2); ```