: 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: [code] MyApplet.setLayout(new GridLayout(3, 4)); [/code] , 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: [code] this.setLayout(new GridLayout(2, 2)); this.add(Label1); this.add(Label2); this.add(Label3); this.add(Label4); [/code] produces a layout of: [code] Label1 Label2
Label3 Label4 [/code] Additional settings like the spacing of the grid cells can be specified. See javadoc for more info on the variables/methods in GridLayout.
Comments
:
:
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:
[code]
MyApplet.setLayout(new GridLayout(3, 4));
[/code]
, 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:
[code]
this.setLayout(new GridLayout(2, 2));
this.add(Label1);
this.add(Label2);
this.add(Label3);
this.add(Label4);
[/code]
produces a layout of:
[code]
Label1 Label2
Label3 Label4
[/code]
Additional settings like the spacing of the grid cells can be specified. See javadoc for more info on the variables/methods in GridLayout.