public class GridLayoutDemo1 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: */
10: public class GridLayoutDemo1 extends JFrame
11: {
12: public static final int WIDTH = 300;
13: public static final int HEIGHT = 200;
14:
15: /**
16: Creates and displays a window of the class BorderLayoutDemo.
17: */
18: public static void main(String[] args)
19: {
20: GridLayoutDemo1 gui1 = new GridLayoutDemo1();
21: gui1.setVisible(true);
22: }
23:
24: public GridLayoutDemo1()
25: {
26: setSize(WIDTH, HEIGHT);
27: addWindowListener(new WindowDestroyer());
28: setTitle("Layout Demonstration");
29: Container content = getContentPane();
30:
31: content.setLayout(new GridLayout(2, 3));
32: JLabel label1 = new JLabel("First");
33: content.add(label1);
34: JLabel label2 = new JLabel("Second");
35: content.add(label2);
36: JLabel label3 = new JLabel("Third");
37: content.add(label3);
38: JLabel label4 = new JLabel("");//Empty string label
39: content.add(label4);
40: JLabel label5 = new JLabel("Fifth");
41: content.add(label5);
42: }
43: }
44:
45:
46:
47: