-1
public void newFilter() {
    RowFilter<ListTable, Object> rf = null;
    //If current expression doesn't parse, don't update.
    try {
        rf = RowFilter.regexFilter(filterText.getText(), 0);
    } catch (java.util.regex.PatternSyntaxException e) {
        return;
    }
    sorter.setRowFilter(rf);

}

I'm using this filter from http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#sorting But this filter seems only able to filter int component on my table (Apart from the first col, all others are strings) . I simply want to create a Filter that leave any row with entered text. I'm relatively new to the language, Thanks very much for your help!

https://i.stack.imgur.com/WxOmz.jpg Here is 3 Image

mKorbel
  • 109,525
  • 20
  • 134
  • 319
qkhanhpro
  • 4,371
  • 2
  • 33
  • 45

1 Answers1

2

Your filter is explicitly applied to column zero, the first column. As shown here, you can include all columns by omitting the indices parameter:

rf = RowFilter.regexFilter(filterText.getText());

Alternatively, you can include specified columns, e.g. columns one through three:

rf = RowFilter.regexFilter(filterText.getText(), 1, 2, 3);

A related example that combines filters is seen here.

Addendum: In helpful comments, @Ordous reminds me that correct usage hinges on the varargs feature, new in Java 5.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Thank you very much! I clearly didn't understand the use of filters well. – qkhanhpro Jul 16 '14 at 12:07
  • I'd give a +1 since the answer is correct, but I really don't like questions that are solvable by just quoting the Javadoc on the method *already used* by the OP... – Ordous Jul 16 '14 at 15:56
  • @Ordous: I tend to agree, but I also have a clear memory of stumbling over [varargs](http://docs.oracle.com/javase/1.5.0/docs/guide/language/varargs.html) when the feature was new to me. – trashgod Jul 16 '14 at 16:03
  • @trashgod True, it can be confusing. But if it says "indices of values to check" on an argument you supply, and you have a problem with some values not being checked, then that's the first place to look, possibly after the regex itself. – Ordous Jul 16 '14 at 16:17