Gui Layout Manager
Gui Layout Manager
Outline
Components and Containers Layout Managers Flow Layout Grid Layout Border Layout Nested Containers with Layouts Overview of Advanced Layout Managers
Layout Managers
Each container has a layout manager, which controls the way the components are positioned in the container. One of the advantages of using layout managers is that there is no need for absolute coordinates where each component is to be placed or the dimensions of the component. The layout manager automatically handles the calculation of these. Programmer only specifies relative positions of the components within the container.
Flow Layout
The Flow Layout manager arranges the components left-to-right, top-to-bottom in the order they were inserted into the container. When the container is not wide enough to display all the components, the remaining components are placed in the next row, etc. Each row is centered.
align alignment used by the manager hgap horizontal gaps between components vgap vertical gaps between components
FlowLayout(align)
align alignment used by the manager A default 5-unit horizontal and vertical gap.
FlowLayout()
Grid Layout
The Grid Layout manager lays out all the components in a rectangular grid. All the components have identical sizes, since the manager automatically stretches or compresses the components as to fill the entire space of the container.
r number of rows in the layout c number of columns in the layout hgap horizontal gaps between components vgap vertical gaps between components
GridLayout(r, c)
r number of rows in the layout c number of columns in the layout No vertical or horizontal gaps.
GridLayout()
Border Layout
The Border Layout manager arranges components into five regions: North, South, East, West, and Center. Components in the North and South are set to their natural heights and horizontally stretched to fill the entire width of the container. Components in the East and West are set to their natural widths and stretched vertically to fill the entire width of the container. The Center component fills the space left in the center of the container.
hgap horizontal gaps between components vgap vertical gaps between components
BorderLayout()
Each of the nested containers can have the same type or totally different type of a layout manager.
Outer Layout: Border Layout Inner Layouts: Border Layout
Flow Layout