< Day Day Up > |
Here's a snapshot of an application that uses a GridLayout . [19]
Figure 23. A simple GUI that uses GridLayout .
GridLayout places components in a grid of cells . Each component takes all of the available space within its cell, and each cell is exactly the same size . If you resize the GridLayoutDemo window, you'll see that GridLayout changes the cell size so that the cells are as large as possible, given the space in the container. Here's the code that creates the GridLayout object and the components it manages . You can find the whole program in GridLayoutDemo.java . pane.setLayout(new GridLayout(0,2)); pane.add(new JButton("Button 1")); pane.add(new JButton("Button 2")); pane.add(new JButton("Button 3")); pane.add(new JButton("Long-Named Button 4")); pane.add(new JButton("5")); The constructor tells the GridLayout class to create an instance that has two columns and as many rows as necessary. The GridLayout APITable 10 lists the constructors available in the GridLayout API. You can find the relevant API documentation online at: http://java.sun.com/j2se/1.4.2/docs/api/java/awt/GridLayout.html. Table 10. GridLayout Constructors
Examples That Use GridLayoutThe following table lists some GridLayout examples.
|
< Day Day Up > |