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