Java Reference
In-Depth Information
Figure 11-3. Using glue in a JMenuBar
Creating Rigid Areas
Because a glue component grows to fill the available space, if you want to have a fixed distance
between components, you need to create a rigid component, or strut . When doing so, you
specify the strut's size. Struts can be two-dimensional, requiring you to specify the width and
height of the component; or, they can be one-dimensional, requiring you to specify either the
width or height.
public static Component createRigidArea(Dimension dimension)
// Two-dimensional
Component rigidArea = Box. createRigidArea(new Dimension(10, 10));
aBox.add(rigidArea);
public static Component createHorizontalStrut(int width)
// One-dimensional: horizontal
Component horizontalStrut = Box. createHorizontalStrut(10);
aBox.add(horizontalStrut);
public static Component createVerticalStrut(int height)
// One-dimensional: vertical
Component verticalStrut = Box. createVerticalStrut(10);
aBox.add(verticalStrut);
Caution Although direction-independent glue created with createGlue() shows no side effects if
you change container direction, creating a rigid area may cause layout problems if the axis is later changed.
(Imagine dragging a menu bar and dropping it along the right side from the top.) That's because the compo-
nent has a dimensionless minimum size. Using createRigidArea() isn't recommended, unless you truly
want a two-dimensional empty component.
 
Search WWH ::




Custom Search