开发者

I've used a row sorter to find if any words in Column (e.x 3) match mine. Any suggestions on what could be changed in my code as it is not working?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜