Note that there are some explanatory texts on larger screens.

plurals
  1. POJTable filtering with JTextField doesn't work
    primarykey
    data
    text
    <p>I have a JTable (DefaultTableModel) and a JTextField. I'd like to filter the JTable with the regex I put into the text field. When I start the program, all entries are shown, but when I enter text into the text field, no rows are displayed even though it should find the text within a row.</p> <pre><code>private void createFilter() { _sorter = new TableRowSorter&lt;DefaultTableModel&gt;(new DefaultTableModel()); JPanel filterPanel = new JPanel(); filterPanel.setLayout(new BorderLayout()); JLabel filterLabel = new JLabel("Filter:"); filterPanel.add(filterLabel, BorderLayout.WEST); _inputField = new JTextField(); _inputField.setColumns(40); filterPanel.add(_inputField, BorderLayout.CENTER); _inputField.getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent de) { newFilter(); } public void removeUpdate(DocumentEvent de) { newFilter(); } public void changedUpdate(DocumentEvent de) { newFilter(); } }); JButton clearButton = new JButton("X"); clearButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { _inputField.setText(""); } }); filterPanel.add(clearButton, BorderLayout.EAST); _mainFrame.add(filterPanel, BorderLayout.SOUTH); } private void newFilter() { RowFilter&lt;DefaultTableModel, Object&gt; rowFilter = null; try { rowFilter = RowFilter.regexFilter(_inputField.getText()); } catch(java.util.regex.PatternSyntaxException ex) { return; } _sorter.setRowFilter(rowFilter); _table.setRowSorter(_sorter); } </code></pre> <p>My debugger shows me, that rowFilter is initialized, so it can't be because of a wrong RegEx. Also newFilter() is called at every keystroke.</p> <p>Thanks in advance. I'd be happy to provide more information if needed.</p> <p>Sincerely, Michael</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload