private void init(final EncodeTableModel model) { setModal(true); setTitle("Encode Production Data"); table.setAutoCreateRowSorter(true); table.setModel(model); table.setRowSorter(model.getSorter()); try { rowCountLabel.setText(numberFormatter.valueToString(table.getRowCount()) + " rows"); } catch (ParseException e) { } table.setRowSelectionAllowed(false); table.setColumnSelectionAllowed(false); filterTextField .getDocument() .addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent e) { updateFilter(); } public void insertUpdate(DocumentEvent e) { updateFilter(); } public void removeUpdate(DocumentEvent e) { updateFilter(); } }); }
/** Update the row filter regular expression from the expression in the text box. */ private void updateFilter() { RowFilter<EncodeTableModel, Object> rf = null; // If current expression doesn't parse, don't update. try { rf = new RegexFilter(filterTextField.getText()); } catch (java.util.regex.PatternSyntaxException e) { return; } model.getSorter().setRowFilter(rf); try { rowCountLabel.setText(numberFormatter.valueToString(table.getRowCount()) + " rows"); } catch (ParseException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } }