The FilterList works with any
Matcher or MatcherEditor.
In this case, we'll use a
TextComponentMatcherEditor. It accepts any
JTextComponent for editing the filter text - in
most cases you'll use a JTextField. Creating the
FilterList and getting your
EventTableModel to use it takes only a few lines
of new code.
/**
* Display a frame for browsing issues.
*/
public void display() {
SortedList sortedIssues = new SortedList(issuesEventList, new IssueComparator());
JTextField filterEdit = new JTextField(10);
FilterList textFilteredIssues = new FilterList(sortedIssues, new TextComponentMatcherEditor(filterEdit, new IssueTextFilterator()));
// create a panel with a table
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
EventTableModel issuesTableModel = new EventTableModel(textFilteredIssues, new IssueTableFormat());
JTable issuesJTable = new JTable(issuesTableModel);
TableComparatorChooser tableSorter = new TableComparatorChooser(issuesJTable, sortedIssues, true);
JScrollPane issuesTableScrollPane = new JScrollPane(issuesJTable);
panel.add(new JLabel("Filter: "), new GridBagConstraints(...));
panel.add(filterEdit, new GridBagConstraints(...));
panel.add(issuesTableScrollPane, new GridBagConstraints(...));
// create a frame with that panel
JFrame frame = new JFrame("Issues");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setSize(540, 380);
frame.getContentPane().add(panel);
frame.show();
}