Open In App

Java AWT | GridLayout Class

GridLayout class represents a layout manager with a specified number of rows and columns in a rectangular grid. The GridLayout container is divided into an equal-sized of rectangles, and one of the components is placed in each rectangle. Every rectangle cell has the same size therefore, they contain a component, which fills the entire cell. When the user changes or adjusts the size of the container, the size of each rectangles changes accordingly.

Constructors of the class:



  1. GridLayout(): It Creates a grid layout with a default of one column per component, in a single row.
  2. GridLayout(int rw, int cl): It creates a grid layout with the specified number of rows and columns.
  3. GridLayout(int rw, int cl, int hgap, int vgap): It creates a grid layout with the specified number of rows and columns with horizontal and vertical gap.

Commonly Used Methods:

Below programs illustrate the GridLayout class:



Note: The above programs might not run in an online IDE. Please use an offline compiler.

Reference: https://docs.oracle.com/javase/7/docs/api/java/awt/GridLayout.html


Article Tags :