The Java Program: Deli.java
1 import java.awt.Container;
2 import java.awt.GridLayout;
3
4 import javax.swing.JPanel;
5 import javax.swing.JFrame;
6 import javax.swing.JCheckBox;
7 import javax.swing.JScrollPane;
8
9 public class Deli extends JPanel {
10
11 private static final String options [] = {
12 "shredded lettuce",
13 "kosher pickle",
14 "mustard",
15 "spicy mustard",
16 "sliced tomato",
17 "green pepper",
18 "black olives",
19 "bean sprouts"
20 };
21
22 Deli () {
23 setLayout (new GridLayout (0,1));
24 for (int i=0; i<options.length; i++) {
25 add (new JCheckBox (options[i]));
26 }
27 }
28
29 public static void main (String [] args) {
30
31 final JFrame frame = new JFrame ("Swing JCheckBox Demo");
32 // Default content pane is JPanel using the JRootPane layout
33 // manager which acts like BorderLayout.
34 frame.getContentPane().add (new Deli ());
35 frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); // Requires Java 1.3
36 frame.pack();
37 frame.setVisible (true);
38 }
39 }