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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With