public class GridLayoutDemo2 extends JFrame
1:
2: import javax.swing.JFrame;
3: import javax.swing.JLabel;
4: import java.awt.Container;
5: import java.awt.GridLayout;
6:
7: /**
8: Simple demonstration of using a layout manager to arrange labels.
9: Note that seven items are added even though only six locations are specified.
10: */
11: public class GridLayoutDemo2 extends JFrame
12: {
13: public static final int WIDTH = 300;
14: public static final int HEIGHT = 200;
15:
16: /**
17: Creates and displays a window of the class BorderLayoutDemo.
18: */
19: public static void main(String[] args)
20: {
21: GridLayoutDemo2 gui2 = new GridLayoutDemo2();
22: gui2.setVisible(true);
23: }
24:
25: public GridLayoutDemo2()
26: {
27: setSize(WIDTH, HEIGHT);
28: addWindowListener(new WindowDestroyer());
29: setTitle("Layout Demonstration");
30: Container content = getContentPane();
31:
32: content.setLayout(new GridLayout(2, 3));
33: JLabel label1 = new JLabel("First");
34: content.add(label1);
35: JLabel label2 = new JLabel("Second");
36: content.add(label2);
37: JLabel label3 = new JLabel("Third");
38: content.add(label3);
39: JLabel label4 = new JLabel("Fourth");//Empty string label
40: content.add(label4);
41: JLabel label5 = new JLabel("Fifth");
42: content.add(label5);
43: JLabel label6 = new JLabel("Sixth");
44: content.add(label6);
45: JLabel label7 = new JLabel("Seventh");
46: content.add(label7);
47: }
48: }
49:
50:
51:
52: