javaswingjtablerowfilter

how to Reverse a RowFilter Work in Java Swing


i have RowFilter that is working with no problem on my code !

sorter = new TableRowSorter < > (((model)));

List < RowFilter < Object, Object >> rfs = new ArrayList < > (2);

if (jRadioButton2.isSelected() == false) {
    String regex1 = "(?i)^" + CompanyNameFilter.getSelectedItem() + "$";
    rfs.add(RowFilter.regexFilter(regex1, 9));
}

if (jRadioButton3.isSelected() == false) {

    if (!CompanyFilterText.getText().equals("") && CompanyFilterText.getText() != null && !CompanyFilterText.getText().equals("تبحث عن شيء ؟")) {
        String regex3 = "(?i)" + CompanyFilterText.getText();
        rfs.add(RowFilter.regexFilter(regex3));
    }
}

if (!searchFilter.getText().equals("") && searchFilter.getText() != null && !searchFilter.getText().equals("تبحث عن شيء ؟")) {
    String regex2 = "(?i)" + searchFilter.getText();
    rfs.add(RowFilter.regexFilter(regex2));
}

RowFilter < Object, Object > af = RowFilter.andFilter(rfs);
sorter.setRowFilter(af);
jTable1.setRowSorter(sorter);

As in my code i use a lot of cases to filter a table by user selected.

however i need to do one think that to Reverse a RowFilter Work so what i need As Example :

simply the filter instead of searching for (AB) And showing the result in the jTable i want it to Hide the result and showing the rest that is not = (AB) !

So i need to Reverse This Working Code :

String regex2 = "(?i)" + searchFilter.getText();
rfs.add(RowFilter.regexFilter(regex2));

Solution

  • Wrap it in RowFilter.notFilter(RowFilter)

    Returns a RowFilter that includes entries if the supplied filter does not include the entry.