Table of Contents Markup Tutorial Interfacing with Java™ Web Services

A presentation component that may contain other presentation components is called a container. A container defers the task of laying out its sub-components to an object called a layout manager. Stated another way, a container uses its layout manager to manage the layout of components on the container’s behalf.

Layout Managers

A layout manager’s sole job is to position and size sub-components within their parent container according to a preset strategy defined by the layout manager. With some exceptions, a container may use a different layout strategy simply by choosing a different layout manager. A layout manager automatically handles the chores of laying out components inside their parent container whenever the content, shape, or size of the container changes.

Two of the most commonly used layout managers are Flow Layout and Border Layout. A panel uses Flow Layout by default, so, it is usually not necessary to specify the layout manager if this default is acceptable. However, if a layout manager is explicitly specified, it must be set before any component is added to the container. See Resource Reference for rules governing the structure of resources.

To see how Flow Layout got its name, run the following and resize the frame. The labels appear to “flow” and wrap inside the panel as static blocks of text. This is just to illustrate the concept of Flow Layout, and should not be construed as a general way to flow text within a container.

Make this object in eNode Sandbox. The result should be similar to the following:

Layout Constraints

Some layout managers lay out their associated container’s sub-components subject to additional constraints. The constraints for a sub-component are set when it is added to its container.

Border Layout and Card Layout are examples of layout managers that support constraints for individual sub-components. Flow Layout and Box Layout, on the other hand, are constraints-free layout managers.

A solid understanding of layout managers is critical for success with views. Experiment with the various layout managers until you are really comfortable with them.


Copyright © 2002 eNode, Inc. All Rights Reserved.