/* ComboBoxDemo.java -- An example showing various combo boxes in Swing.
- Copyright (C) 2005, Free Software Foundation, Inc.
+ Copyright (C) 2005, 2006, Free Software Foundation, Inc.
This file is part of GNU Classpath examples.
}
}
+ private JPanel content;
private JCheckBox comboState1;
private JComboBox combo1;
private JComboBox combo2;
{
super(title);
JPanel content = createContent();
+ // initFrameContent() is only called (from main) when running this app
+ // standalone
+ }
+
+ /**
+ * When the demo is run independently, the frame is displayed, so we should
+ * initialise the content panel (including the demo content and a close
+ * button). But when the demo is run as part of the Swing activity board,
+ * only the demo content panel is used, the frame itself is never displayed,
+ * so we can avoid this step.
+ */
+ public void initFrameContent()
+ {
JPanel closePanel = new JPanel();
JButton closeButton = new JButton("Close");
closeButton.setActionCommand("CLOSE");
*/
JPanel createContent()
{
- JPanel content = new JPanel(new BorderLayout());
- JPanel panel = new JPanel(new GridLayout(6, 1));
- panel.add(createPanel1());
- panel.add(createPanel2());
- panel.add(createPanel3());
- panel.add(createPanel4());
- panel.add(createPanel5());
- panel.add(createPanel6());
- content.add(panel);
+ if (content == null)
+ {
+ content = new JPanel(new BorderLayout());
+ JPanel panel = new JPanel(new GridLayout(6, 1));
+ panel.add(createPanel1());
+ panel.add(createPanel2());
+ panel.add(createPanel3());
+ panel.add(createPanel4());
+ panel.add(createPanel5());
+ panel.add(createPanel6());
+ content.add(panel);
+ }
return content;
}
e.printStackTrace();
}
ComboBoxDemo app = new ComboBoxDemo("ComboBox Demo");
+ app.initFrameContent();
app.pack();
app.setVisible(true);
}