1 of 18

Adanced Java Programming

Layout Managers

Smt.M.Jeevana Sujitha

Assistant Professor

Department of Computer Science and Engineering

SRKR Engineering College, Bhimavaram, A.P. - 534204

2 of 18

OBJECTIVES

The Objective of this lecture is

  • To learn about different types of Layout Managers in AWT.

3 of 18

Need of Layout Managers

4 of 18

Layout Managers

What is Layout Manager?

  • It is used to arrange the components in a particular manner.
  • It is an interface that is implemented by all classes of layout managers.

5 of 18

Layout Managers

  • There are six layouts available in AWT they are
  • Border Layout
  • Grid Layout
  • Flow Layout
  • Card Layout
  • Grid Bag Layout
  • Box Layout

6 of 18

Layout Managers

Border Layout:

  • The border layout is used to arrange the components in five regions that is north, south, east, west and center.
  • Each region may contain one component only.
  • It is the default layout of frame or window.
  • It provides five constants for each

region.

7 of 18

Layout Managers

Border Layout:

  • The border layout provides five constants for each region. They are
  • public static final int NORTH
  • public static final int SOUTH
  • public static final int EAST
  • public static final int WEST
  • public static final int CENTER Constructors:

BorderLayout() : Creates a border layout but with no gaps between the components

8 of 18

Layout Managers

Grid Layout:

  • It is used to

arrange the components in a

rectangular grid.

  • One component is displayed in each rectangle.

9 of 18

Layout Managers

Grid Layout:

  • 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 gap between the components.
  • GridLayout(int rows,int columns, int hgap,int vgap): creates a grid layout with the given rows and columns along with horizontal and vertical gaps.

10 of 18

Layout Managers

Flow Layout:

  • It is used to arrange the components in a line one after another.
  • It is the default layout of applet or panel.

11 of 18

Layout Managers

  • Fields of FlowLayout:
  • public static final int LEFT
  • public static final int RIGHT
  • public static final int CENTER
  • public static final int LEADING
  • public static final int TRAILING

12 of 18

Layout Managers

Constructors of FlowLayout:

  1. FlowLayout() : creates a flow layout with centered alignment and a default 5 unit horizontal and vertical gap.
  2. FlowLayout(int align): creates a flow layout with the given alignment and a default horizontal and vertical gap.
  3. FlowLayout(int align, int hgap, int vgap): creates a flow layout with the given alignment and the given horizontal and vertical gap.

13 of 18

Layout Managers

Card Layout:

  • The CardLayout class manages the component in such a manner that only one component is visible at a time.
  • It treats each component as a card.

14 of 18

Layout Managers

  • Constructors:
  • CardLayout(): creates a card layout with zero horizontal and zero vertical gap.
  • CardLayout(int hgap, int vgap): creates a card layout with the given horizontal and vertical gap.

15 of 18

Layout Managers

GridBag Layout:

  • The GridBagLayout class is used to align the components vertically, horizontally or along their base line.
  • Each GridBagLayout object maintains a dynamic rectangular grid of cells.
  • Each component occupies one or more cells known as its display area.

16 of 18

Layout Managers

Box Layout:

  • The BoxLayout is used to arrange the components either vertically or horizontally.
  • For this purpose it provides four constants. They are
  • public static final int X_AXIS
  • public static final int Y_AXIS
  • public static final int LINE_AXIS
  • public static final int PAGE_AXIS

BoxLayout( Container c, int axis) : creates a box layout that arranges the components with the given axis.

17 of 18

Layout Managers

public static final int X_AXIS

public static final int Y_AXIS

18 of 18

THANK YOU