How can I perform a case-insensitive filter on a JTable?

后端 未结 2 1153
野趣味
野趣味 2020-12-01 21:12

I am making a table with a text field below it where you can type in a word to filter the table. It works, but what I want to do is be able to filter it with the word typed

相关标签:
2条回答
  • 2020-12-01 21:49
    rowSorter.setStringConverter(new TableStringConverter() {
        @Override
        public String toString(TableModel model, int row, int column) {
            return model.getValueAt(row, column).toString().toLowerCase();
        }
    });
    rowSorter.setRowFilter(RowFilter.regexFilter(jtfFilter.getText().toLowerCase()));
    
    0 讨论(0)
  • 2020-12-01 21:51

    Add the standard regex case-insensitivity flag:

    rowSorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
    

    I've tested this with your SSCCE (thanks for providing that) and it works.

    0 讨论(0)
提交回复
热议问题