Although the issues list contains over 100 issues, there's only a
few unique users. Our users list has many duplicates - one for each
occurrence of a user in the issues list. Duplicate removal is solved
quickly and easily by UniqueList.
// derive the users list from the issues list
EventList usersNonUnique = new IssueToUserList(issuesEventList);
UniqueList usersEventList = new UniqueList(usersNonUnique);Finally, you can display the users list in a
JList. In the next chapter, we'll use that
JList in a filter for our issues list.
/**
* 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()));
// derive the users list from the issues list
EventList usersNonUnique = new IssueToUserList(issuesEventList);
UniqueList usersEventList = new UniqueList(usersNonUnique);
// create the issues table
EventTableModel issuesTableModel = new EventTableModel(textFilteredIssues, new IssueTableFormat());
JTable issuesJTable = new JTable(issuesTableModel);
TableComparatorChooser tableSorter = new TableComparatorChooser(issuesJTable, sortedIssues, true);
JScrollPane issuesTableScrollPane = new JScrollPane(issuesJTable);
// create the users list
EventListModel usersListModel = new EventListModel(usersEventList);
JList usersJList = new JList(usersListModel);
JScrollPane usersListScrollPane = new JScrollPane(usersJList);
// create the panel
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
panel.add(new JLabel("Filter: "), new GridBagConstraints(...));
panel.add(filterEdit, new GridBagConstraints(...));
panel.add(new JLabel("Reported By: "), new GridBagConstraints(...));
panel.add(usersListScrollPane, 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();
}