Table of Contents Markup Tutorial Interfacing with Java™ Web Services

There are more ways to arrange presentation components inside containers than just flowing them in with Flow Layout, or snapping them in place with Border Layout. The Box component uses a layout manager called Box Layout that specializes in laying out components either horizontally or vertically within a container in the order that they are added to the container.

Box Component

The orientation of a box is specified by the orientation attribute of the box element. JFC users will recognize this as the axis argument passed to the constructor for javax.swing.Box. The following example shows how to use the box element type.

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

If the orientation attribute is missing, or the value is not recognized, orientation="horizontal" is assumed, as shown in the next example. In this example, we alternate the background color of labels so that you can clearly see where one ends, and the next one begins.

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

Box Limitations and Box Layout

Versions of the Java™ Runtime Environment (JRE) that are earlier than version 1.4 support only a small number of attributes for the Box component. As a result, several features available for standard presentation components are not available for a box component. However, an easy workaround for these older environments is to replace the box element with a panel element that uses a boxLayout element. The previous example is reworked below using this approach, and the result is identical.


Copyright © 2002 eNode, Inc. All Rights Reserved.