searchnameField = new JTextField();
searchnameField.addKeyListener(new KeyAdapter() {
public void search(String in) {
TableRowSorter<DefaultTableModel> t = new TableRowSorter<DefaultTableModel>();
table.setRowSorter(t);
t.setRowFilter(RowFilter.regexFilter("^"+in, 3));
}
public void keyReleased(KeyEvent e) {
String in = searchnameField.getText();
search(in);
}
});
searchnumberField = new JTextField();
searchnumberField.setBounds(540, 130, 362, 34);
panel1.a开发者_如何转开发dd(searchnumberField);
searchnumberField.setColumns(10);
searchnumberField.addKeyListener(new KeyAdapter() {
public void search(String in) {
TableRowSorter<DefaultTableModel> s = new TableRowSorter<DefaultTableModel>();
table.setRowSorter(s);
s.setRowFilter(RowFilter.regexFilter("^"+in, 1));
}
public void keyReleased(KeyEvent e) {
String idn = searchnumberField.getText();
search(idn);
}
});
As you can see in my code, I have have set 2 textfields and as the user enters each letter, my row sorter should be singling out the row/rows with the specific String that matches mine, however that doesn't seem to be the case, it doesn't sort through any of my rows or data. Also, I am relatively new to GUI and apologize if my mistake is obvious.(3 and 1 represent the column indices). If any more information is required please comment.
精彩评论