RowFilter.regexFilter multiple columns

I am currently using the following to filter my JTable

RowFilter.regexFilter( 
         Pattern.compile(textField.getText(), 
         Pattern.CASE_INSENSITIVE).toString(),     columns );

How can I format mine textFieldor a filter, so if I want to filter multiple columns, I can do it. Now I can filter multiple columns, but my filter can only be one of the columns

An example may help my explanation better:

Name Grade GPA
Zac   A    4.0
Zac   F    1.0
Mike  A    4.0
Dan   C    2.0

Text field will contain Zac Aor something like that, and it will show the first line of Zac, if columnswas int[]{0, 1}. Right now, if I do this, I get nothing. The filter Zacworks, but I get both Zac. Aalso works, but I would get Zac A 4.0and Mike A 3.0.

Hope I explained my problem well. Please let me know if you do not understand.

+5
3

, AndFilter include(). RegexFilter , , , .

, , (?i) . , , , , , CASE_INSENSITIVE.

EDIT: AndFilter RegexFilters, . , foo bar , , RegexFilter foo|bar . AndFilter -, AndFilter: , . , Zac A :

List<RowFilter<Object,Object>> rfs = 
    new ArrayList<RowFilter<Object,Object>>(2);
filters.add(RowFilter.regexFilter("(?i)^Zac$", 0));
filters.add(RowFilter.regexFilter("(?i)^A$", 1));
RowFilter<Object,Object> af = RowFilter.andFilter(rfs);

, ( , , ), , , :

String regex = "(?i)^" + Pattern.quote(input) + "$";
+11

, :

RowFilter<PublicationTableModel, Object> rf = null;
List<RowFilter<Object,Object>> rfs = 
            new ArrayList<RowFilter<Object,Object>>();

try {
    String text = txtFilter.getText();
    String[] textArray = text.split(" ");

    for (int i = 0; i < textArray.length; i++) {
        rfs.add(RowFilter.regexFilter("(?i)" + textArray[i], 0, 1, 2, 4));
    }

    rf = RowFilter.andFilter(rfs);

} catch (java.util.regex.PatternSyntaxException e) {
        return;
}

sorter.setRowFilter(rf);

, , . , andFilter .

+5
RowFilter<TableModel, Object> filter =
    RowFilter.orFilter(Arrays.asList(RowFilter.regexFilter(lookup,0),
    RowFilter.regexFilter(lookup, 1)));

RowFilter<TableModel, Object> filter =
    RowFilter.regexFilter(Pattern.compile(lookup,Pattern.CASE_INSENSITIVE).toString(),0,1);

0 and 1 - column numbers

+1
source

All Articles