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