Java Reference
In-Depth Information
LISTING 9.7
The Full Text of FormatFrame2.java
1: import javax.swing.*;
2:
3: public class FormatFrame2 extends JFrame {
4: String[] formats = { “Atom”, “RSS 0.92”, “RSS 1.0”, “RSS 2.0” };
5: JComboBox formatBox = new JComboBox();
6:
7: public FormatFrame2() {
8: super(“Choose a Format”);
9: setSize(220, 150);
10: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
11: JPanel pane = new JPanel();
12: JLabel formatLabel = new JLabel(“Output formats:”);
13: pane.add(formatLabel);
14: for (int i = 0; i < formats.length; i++)
15: formatBox.addItem(formats[i]);
16: pane.add(formatBox);
17: add(pane);
18: setVisible(true);
19: }
20:
21: public static void main(String[] arguments) {
22: FormatFrame2 ff = new FormatFrame2();
23: }
24: }
9
Figure 9.6 shows the application as the combo box is expanded so that a value can be
selected.
FIGURE 9.6
The FormatFrame2
application.
Lists
The last Swing component to be introduced today is similar to combo boxes. Lists ,
which are represented by the JList class, enable one or more values to be selected from
a list.
 
 
Search WWH ::




Custom Search