When both the number of rows and the number of columns have been set to non-zero values, either by a constructor or by the setRows and setColumns methods, the number of columns specified is ignored. Instead, the number of columns is determined from the specified number or rows and the total number of components in the layout. So, for example, if three rows and two columns have been specified and nine components are added to the layout, then they will be displayed as three rows of three columns. Specifying the number of columns affects the layout only when the number of rows is set to zero.
There are three forms of constructors for GridLayout
(1) public GridLayout()
Creates a grid layout with a default of one column per component, in a single row.
(2) public GridLayout(int rows,int cols)
Creates a grid layout with the specified number of rows and columns. All components in the layout are given equal size.
One, but not both, of rows and cols can be zero, which means that any number of objects can be placed in a row or in a column.
rows - the rows, with the value zero meaning any number of rows.
cols - the columns, with the value zero meaning any number of columns.
Hope this is clear. You can refer about this at
http://java.sun.com/products/jdk/1.2/docs/api/index.html