JavaLayoutManager
JavaLayoutManager
Layout Manager:
A layout manager is an object that controls the size and position (layout) of components inside a
Container object. For example, a window is a container that contains components such as buttons
and labels. The layout manager in effect for the window determines how the components are
sized and positioned inside the window. A container can contain another container. For example,
a window can contain a panel, which is itself a container.
FlowLayout
BorderLayout
GridLayout
GridBagLayout
CardLayout
FlowLayout( )
FlowLayout(int how)
FlowLayout(int how, int horz, int vert)
The first form creates the default layout, which centers components and leaves five pixels of
space between each component.
The second form lets you specify how each line is aligned. Valid values for how are as follows:
FlowLayout.LEFT
FlowLayout.CENTER
FlowLayout.RIGHT
The third form allows specifying the horizontal and vertical space left between components in
horz and vert, respectively.
import java.awt.*;
import java.applet.*;
BorderLayout( )
BorderLayout(int horz, int vert)
The first form creates a default border layout. The second form allows you to specify the
horizontal and vertical space left between components in horz and vert, respectively.
GridLayout( )
GridLayout(int numRows, int numColumns )
GridLayout(int numRows, int numColumns, int horz,
int vert)
The first form creates a single-column grid layout. The second form creates a grid layout with
the specified number of rows and columns. The third form allows you to specify the horizontal
and vertical space left between components in horz and vert, respectively.
import java.awt.*;
import java.applet.*;
CardLayout:
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. This can be useful for user interfaces
with optional components that can be dynamically enabled and disabled upon user input. We can
prepare the other layouts and have them hidden, ready to be activated when needed. CardLayout
provides the following two constructors:
CardLayout( )
CardLayout(int horz, int vert)
The first form creates a default card layout. The second form allows you to specify the horizontal
and vertical space left between components in horz and vert, respectively.