
II
8.6 Specifying Look and Feel
12 3
Figure 8.8:
GridLayout.
button3 = new JButton("component 3");
cp.add(button3, BorderLayout.CENTER);
button4 = new JButton("component 4");
cp.add(button4, BorderLayout.EAST);
button5 = new JButton("component 5");
cp.add(button5, BorderLayout.SOUTH);
8.5.3 GridLayout
In a GridLayout container, components are placed in a grid of cells. The statement
cp. setLayout(new GridLayout(r, c)) ;
specifies a GridLayout with r rows and c columns for the content pane cp. By default, there are
no gaps between components. Again, if gaps are desired, use the constructor GridLayout(r,
c,