2. INTRODUCTION
Java uses Layout Managers to define the location
and size of Graphical User Interface components.
Java technology uses Layout Managers to define
the location and size of Graphical User Interface
components.. A Layout Manager implements a
layout policy that defines constraints between
components in a container.
3. TYPES OF LAYOUT MANAGER
Java technology provides the following Layout
Managers, each of which implements the Layout
Manager interface:
Flow Layout
Grid Layout
Border Layout
CardLayout
4. DEFAULT LAYOUT MANAGER
The FlowLayout is the default Layout Manager for
Panel, and hence the Applet class. The
BorderLayout is the default Layout Manager for
Window class and its subclasses (Frame and
Dialog).
5. SETTING LAYOUT MANAGERS
The following method defined in the Container class
can be used for setting layout managers.
void setLayout(LayoutManager mgr);
6. FLOWLAYOUT MANAGER
FlowLayout places component in rows from left to
right. Components towards the end of row are
written on next row, if there is not enough space in
the current row. The FlowLayout honors the
specified size of a component.
7. CONTD….
The following constructors of FlowLayout are
provided by AWT –
FlowLayout();
FlowLayout(int alignment);
FlowLayout(int alignment, int hor_gap, int
ver_gap);
9. GRIDLAYOUT MANAGER
A Grid Layout Manager places the components in a
rectangular grid. Each component's position is
identified by a column and row. All the cells in the
grid have same size and width. Each component is
stretched to the cell size. So a Grid Layout ignores
the Component's preferred size.
10. CONTD….
The GridLayout class provides the following
constructors:
GridLayout();
GridLayout(int rows, int columns);
GridLayout(int rows, int columns, int
hor_gap, int ver_gap);
12. BORDERLAYOUT MANAGER
A BorderLayout Manager divides the window into
five regions - North, East, West, South and Center.
A component can be explicitly added to one of the
regions using the add() method of the Container
class. Any space left over by the component in
North, East, South and West is occupied by the
component in Center.
13. CONTD:
The BorderLayout class defines the following
constructors :
BorderLayout();
BorderLayout(int hor_gap, int ver_gap);
15. CARD LAYOUT
The CardLayout class is unique among the other
layout managers in that it stores several different
layouts. Each layout can be thought of as being on
a separate index card in a deck that can be shuffled
so that any card is on top at a given time.