static void createAndShowGui() {
JFrame frmSql = new JFrame();
JTabbedPane tabbedPane = new JTabbedPane();
Action refreshEvents = null, refreshCompletedEvents = null;
tabbedPane.addTab("Events", createTab(retrieveData("events"), refreshEvents));
// more tabs
tabbedPane.addTab("Completed Events", createTab(retrieveData("completed"), refreshCompletedEvents));
frmSql.setContentPane(tabbedPane);
}
static JComponent createTab(JComponent content, Action refreshAction) {
JPanel p = new JPanel(new BorderLayout());
p.add(content, BorderLayout.CENTER);
JPanel btns = new JPanel();
BoxLayout layout = new BoxLayout(btns, BoxLayout.LINE_AXIS);
btns.setLayout(layout);
JButton refreshBtn = new JButton(refreshAction);
btns.add(refreshBtn);
btns.add(Box.createHorizontalGlue());
p.add(btns, BorderLayout.PAGE_END);
return p;
}
当然,如果retriveData
很耗时,不应该从 EDT 调用