Layout managers enable you to control the way in which visual components are arranged in GUI forms by determining the size and position of components within containers. This is accomplished by implementing the LayoutManager interface.
By default, new forms created with the GUI Builder use a FreeDesign paradigm which enables you to lay out your form using visual guidelines that automatically suggest optimal alignment and spacing of components. As you work, the GUI Builder translates your design decisions into a functional UI without requiring you to specify a layout manager. Because FreeDesign employs a dynamic layout model, whenever you resize the form or switch locales the GUI adjusts to accommodate your changes without changing the relationships between components.
Layout Managers provided in the IDE
If you are working with forms created in earlier versions of the IDE or want your form to be compatible with standard Java classes, for example, you can specify a layout manager for your forms.
You can choose from the following Layout Managers in the IDE:
FlowLayout ()
arranges components in a container like words on a page.
It fills the top line from left to right until no more components can fit,
continuing the same way on each successive line below.
BorderLayout ()
arranges components along the edges or the middle of their container. Using
BorderLayout, you can place components in five possible positions: North,
South, East, West, and Center corresponding to the container's top, bottom,
right and left edges and interior area.
GridLayout ()
places components in a grid of equally sized cells, adding them to the grid from
left to right and top to bottom.
GridBagLayout ()
is a powerful layout manager
that provides precise control over all aspects of the layout even when
the container is resized, using a complex set of component
properties called "constraints."
It is particularly useful for multiplatform Java
applications as it enables you to create a free-form layout that
maintains a consistent appearance across platforms.
GridBagLayout places components in a grid of rows and columns in which grid cells do not all have to be the same size. In addition, components can span multiple rows, columns, or both. For more information about using GridBagLayout see Using the GridBag Customizer .
CardLayout ()
provides a means of managing two or more components occupying the same
display area. When using CardLayout each component is like a card in a
deck, where all cards are the same size and only the top card is visible
at any time. Since the components share the same display space, at design
time you must select individual components using the Inspector window.
BoxLayout () allows
multiple components to be arranged either vertically or horizontally, but
not both. Components managed by BoxLayout are arranged from left to right
or top to bottom in the order they are added to the container. Components
in BoxLayout do not wrap to a second row or column when more components
are added or even when the container is resized.
AbsoluteLayout () is
a special IDE layout manager that enables components to be placed exactly
where you want them in the form, move them around in the IDE, and resize
them using their selection borders. It is particularly useful for making
prototypes since there
are no formal limitations and you do not have to enter any
property settings. However, it is not recommended for production applications
since the fixed locations and sizes of components do not change with the
environment.
The Null Layout ()
is used to design forms without any layout manager at all.
Like the AbsoluteLayout, it is useful for making quick prototypes but is not
recommended for production applications, as the fixed locations and sizes of
components do not change when the environment changes.