Java Reference
In-Depth Information
Display 17.9 The GridLayout Manager (part 1 of 2)
1
import javax.swing.JFrame;
2
import javax.swing.JLabel;
3
import java.awt.GridLayout;
4 public class GridLayoutJFrame extends JFrame
5{
6
public static final int WIDTH = 500;
7
public static final int HEIGHT = 400;
8
public static void main(String[] args)
9
{
10
GridLayoutJFrame gui = new GridLayoutJFrame(2, 3);
11
gui.setVisible( true );
12
}
13
public GridLayoutJFrame( int rows, int columns )
14
{
15
super ();
16
setSize(WIDTH, HEIGHT);
17
setTitle("GridLayout Demonstration");
18
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
19
setLayout( new GridLayout(rows, columns ));
20
JLabel label1 = new JLabel("First label");
21
add(label1);
22
JLabel label2 = new JLabel("Second label");
23
add(label2);
24
JLabel label3 = new JLabel("Third label");
25
add(label3);
26
JLabel label4 = new JLabel("Fourth label");
27
add(label4);
28
JLabel label5 = new JLabel("Fifth label");
29
add(label5);
30
}
31
}
Search WWH ::




Custom Search