92
Java GridLayout
The Java GridLayout class is used to arrange the components in a rectangular grid. One component is displayed in each rectangle.
Constructors of GridLayout class
- GridLayout(): creates a grid layout with one column per component in a row.
- GridLayout(int rows, int columns): creates a grid layout with the given rows and columns but no gaps between the components.
- GridLayout(int rows, int columns, int hgap, int vgap): creates a grid layout with the given rows and columns along with given horizontal and vertical gaps.
Example of GridLayout class: Using GridLayout() Constructor
The GridLayout() constructor creates only one row. The following example shows the usage of the parameterless constructor.
FileName: GridLayoutExample.java
Output:
Example of GridLayout class: Using GridLayout(int rows, int columns) Constructor
FileName: MyGridLayout.java
Output:
Example of GridLayout class: Using GridLayout(int rows, int columns, int hgap, int vgap) Constructor
The following example inserts horizontal and vertical gaps between buttons using the parameterized constructor GridLayout(int rows, int columns, int hgap, int vgap).
FileName: GridLayoutExample1.java
Output:
Next TopicFlowLayout