Java Reference
In-Depth Information
LISTING 11.3
Continued
16: public Bunch() {
17: super(“Bunch”);
18: setSize(260, 260);
19: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
20: JPanel pane = new JPanel();
21: GridLayout family = new GridLayout(3, 3, 10, 10);
22: pane.setLayout(family);
23: pane.add(marcia);
24: pane.add(carol);
25: pane.add(greg);
26: pane.add(jan);
27: pane.add(alice);
28: pane.add(peter);
29: pane.add(cindy);
30: pane.add(mike);
31: pane.add(bobby);
32: add(pane);
33: setVisible(true);
34: }
35:
36: public static void main(String[] arguments) {
37: Bunch frame = new Bunch();
38: }
39: }
Figure 11.3 shows this application.
FIGURE 11.3
Nine buttons
arranged in a 3 × 3
grid layout.
One thing to note about the buttons in Figure 11.3 is that they expanded to fill the space
available to them in each cell. This is an important difference between grid layout and
some of the other layout managers, which display components at a much smaller size.
 
Search WWH ::




Custom Search