javaregexswingjtablerowfilter

JTable RowFilter - case insensitive


I'm having a problem with a RowFilter, I'm trying to make it display data without it being case sensitive.

DefaultTableModel table=(DefaultTableModel)tablicaEv.getModel();
String search=jTextField1.getText();
TableRowSorter<DefaultTableModel> tr=new TableRowSorter<> (table);
tablicaEv.setRowSorter(tr);
tr.setRowFilter(RowFilter.regexFilter(search);

I tried adding "(?!)" in the RegexFilter but that only makes my table not display any data at all when I try searching. What am I doing wrong?


Solution

  • You probably wanted to prefix the search string with (?i) (case insensitive match).

    (?!) is a "zero-width negative lookahead" matching nothing which will never match if anything follows it.