I have a JTable that am Filtering in relation to JTextField input. It is only Filtering Rows based on the first characters. For example if My Column 2 has Values:
VALUES PARAMETER
PARAMETER VALUES
.
.
When I type V into the JTextfield it will show the row with VALUES PARAMETER
and leave the row with PARAMETER VALUES
I need an advanced Filter such that when I type V it will be able to show me the Two rows or any other rows where there is a Name Starting with the Value typed in the JTextField: Here is My Filter....(Part)
jtfSearch.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
newFilter();
}
public void insertUpdate(DocumentEvent e) {
newFilter();
}
public void removeUpdate(DocumentEvent e) {
newFilter();
}
});
My Filter Method:
public void newFilter() {
RowFilter< MyTableModel, Object> rf = null;
try {
rf = RowFilter.regexFilter("^" + jtfSearch.getText(), 1);
} catch (Exception as) {
System.err.println(as);
return;
}
sorter.setRowFilter(rf);
}
Is it an Issue of the Regex filter or what Should I do?
I assume that jtfSearch.getText()
returns the text from the entire row, is this correct? If so, then presumably the issue is just that you have "^"
at the start of your regex, take this out and it should match anywhere in the full row content.