Java Reference
In-Depth Information
To help you visualize this mixed alignment behavior, Figure 10-11 shows two BoxLayout
containers. The left container has two components, one with a left alignment (the button
labeled 0.0) and another with a right alignment (the button labeled 1.0). Here, you can see that
the left edge of the right component is aligned to the right edge of the left component, with the
common edge being the centerline of the container. The right container shows additional
components placed between the 0.0 and 1.0 alignment settings. The label of each button repre-
sents its alignment setting.
Figure 10-11. Two y-axis BoxLayout containers with mixed horizontal alignments
For a horizontal box, the y alignment works the same relative to the top and bottom of the
components on an x-axis, as illustrated in Figure 10-12.
Figure 10-12. Two x-axis BoxLayout containers with mixed vertical alignments
Laying Out Larger Components
In the examples so far, the size of the components is always smaller than the space available.
Those examples demonstrate a subtle difference between Swing and the original AWT compo-
nents. The default maximum size of Swing components is the preferred size of the component.
With AWT components, the default maximum size is a dimension with a width and height of
Short.MAX_VALUE . If the previous examples had used AWT Button components instead of Swing
JButton components, you would see surprisingly different results. You would also see different
results if you manually set the maximum size property of the components to some value wider
or higher than the screen for the appropriate BoxLayout . Using AWT Button components makes
things a little easier to demonstrate.
Figure 10-9 showed three y-axis BoxLayout containers in which the components inside the
container share the same horizontal alignment setting and the maximum size of each button is
constrained. If the component's maximum size is unconstrained, or just larger than the container,
you see something like Figure 10-13, in which the y-axis BoxLayout container has four Button
 
Search WWH ::




Custom Search