Layout Managers
In Java, Layout Managers is used for arranging the components in order. LayoutMananger is an interface which implements the classes of the layout manager.
Below are some of the class which are used for the representation of layout manager.
1. java.awt.BorderLayout
2. java.awt.FlowLayout
3. java.awt.GridLayout
4. java.awt.CardLayout
5. javax.swing.BoxLayout
Border Layout
BorderLayout is used, when we want to arrange the components in five regions. The five regions can be north, south, east, west and the centre. There are 5 types of constructor in Border Layout. They are as following:
1. public static final int NORTH
2. public static final int SOUTH
3. public static final int EAST
4. public static final int WEST
5. public static final int CENTER
Example:
Â
Grid Layout
Grid Layout is used, when we want to arrange the components in a rectangular grid.
There are 3 types of constructor in Grid Layout. They are as following:
1. GridLayout()
2. GridLayout(int rows, int columns)
3. GridLayout(int rows, int columns, inthgap, int vgap)
Example:
Â
Flow Layout
Flow Layout is used, when we want to arrange the components in a sequence one after another.
There are 3 types of constructor in the Flow Layout. They are as following:
1. FlowLayout()
2. FlowLayout(int align)
3. FlowLayout(int align, inthgap, intvgap)
Example:
Â
Box Layout
Box Layout is used, when we want to arrange the components vertically or horizontally.
BoxLayout(Container c, int axis)is the only constructor in the Box Layout
Example:
Â
Example:
Â
Card Layout
Card Layout is used, when we want to see only one component at a time.
There are 2 types of constructor in the Card Layout. They are as following:
1. CardLayout()
2. CardLayout(inthgap, intvgap)
Example:
Â