: How to use GridBageLayout in java
Call the Container.setLayout() of the container object, whose layout you want to change, and specify a GridLayout object. The GridLayout object can be made on the fly with new:
MyApplet.setLayout(new GridLayout(3, 4));
, or be stored in a variable. The parameters define the number of grid cells in x, y directions.
Each component, which is added to the Container, is added row by row from top-left to bottom-right. Example:
this.setLayout(new GridLayout(2, 2));
produces a layout of:
Additional settings like the spacing of the grid cells can be specified. See javadoc for more info on the variables/methods in GridLayout.