The grid constraint grid(Object[][] 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 4.1.
main class TestGrid {
component Button bt[5];
grid({{bt[0],bt[0],bt[1]},
{bt[3],bt[4],bt[1]},
{bt[3],bt[2],bt[2]}});
}