We use Glazed Lists to display our issue list in a few simple steps. We create a
BasicEventList
and populate it with a
Collection
of issues. Then we create a
EventListModel
and specify that as the model for our
JList
widget. Finally we display it all on screen.
import java.util.*; import java.io.*; import javax.swing.*; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; // a simple issues library import ca.odell.issuezilla.*; // glazed lists import ca.odell.glazedlists.*; import ca.odell.glazedlists.swing.*; /** * An IssueBrowser is a program for finding and viewing issues. * * @author <href="mailto:jesse@odel.on.ca">Jesse Wilson</a> */ public class IssuesBrowser { /** event list that hosts the issues */ private EventList issuesEventList = new BasicEventList(); /** * Create an IssueBrowser for the specified issues. */ public IssuesBrowser(List issues) { issuesEventList.addAll(issues); } /** * Display a frame for browsing issues. */ public void display() { // create a panel with a table JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); EventListModel issuesListModel = new EventListModel(issuesEventList); JList issuesJList = new JList(issuesListModel); JScrollPane issuesListScrollPane = new JScrollPane(issuesJList); panel.add(issuesListScrollPane, 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(); } /** * Launch the IssuesBrowser from the commandline. */ public static void main(String[] args) { if(args.length != 1) { System.out.println("Usage: IssuesBrowser <file>"); return; } // load some issues List issues = null; try { IssuezillaXMLParser parser = new IssuezillaXMLParser(); InputStream issuesInStream = new FileInputStream(args[0]); issues = parser.loadIssues(issuesInStream, null); issuesInStream.close(); } catch(IOException e) { e.printStackTrace(); return; } // create the browser IssuesBrowser browser = new IssuesBrowser(issues); browser.display(); } }