Next: The table constraint
Up: Layout constraints
Previous: The sameXXX constraint
The grid constraint grid(DJComponent[][] comps) takes a two-dimensional array of components comps and ensures that the components are placed in a grid board. Suppose the array comps is
.
Then, the grid board is
and each grid (i,j) is covered by the component comps[i][j]. Notice that a component can cover several consecutive grids if it appears in the array several times.
For example, the following program displays the panel shown in Figure
.
class TestGrid {
dj Button bt[5];
for (i in 0..4) bt[i].text == String(i);
grid({{bt[0],bt[0],bt[1]},
{bt[3],bt[4],bt[1]},
{bt[3],bt[2],bt[2]}});
}
Figure:
Grid constraint.
 |
Neng-Fa Zhou
1999-02-16