Java Reference
In-Depth Information
Figure 10-15. Y-axis BoxLayout containers with different vertical alignments, unconstrained size,
and only one alignment at minimum/maximum
OverlayLayout Class
As its name implies, the OverlayLayout class is for layout management of components that lie
on top of one another. When using add(Component component) , the order in which you add
components to a container with an OverlayLayout manager determines the component layering. If
you use add(Component component, int index) instead, you can add components in any order.
Although OverlayLayout implements the LayoutManager2 interface, like BoxLayout it currently
doesn't use any constraints.
Determining the two-dimensional position of the components requires the layout manager
to examine the x and y alignment properties of the contained components. Each component
will be positioned such that its x and y alignment properties define a point shared by all the
components, called the axis point of the layout manager. If you multiply the alignment value
by the component's size in each appropriate direction, you'll get each part of the axis point for
that component.
After the axis point is determined for each component, the OverlayLayout manager calcu-
lates the position of this shared point within the container. To calculate this position, the layout
manager averages the different alignment properties of the components, and then multiplies
each setting by the width or height of the container. This position is where the layout manager
places the axis point, and the components are then positioned over this shared point.
For example, suppose you have three buttons: a 25×25 white button on top of a 50×50 gray
button on top of a 100×100 black button. If the x and y alignment of each button is 0.0f, the
shared axis point for the three components is their upper-left corner, and the components are
all in the upper-left corner of the container. Figure 10-16 shows how this might appear.
If the x and y alignment of each button is 1.0f, the axis point for the three components is
their bottom-right corner, and the components are in the bottom-right corner of the container.
Figure 10-17 shows this appearance.
 
Search WWH ::




Custom Search