Java Reference
In-Depth Information
Working with Box.Filler
The Box class has an inner class Box.Filler to help you create invisible components for better
component positioning within a container whose layout manager is BoxLayout . By directly
manipulating the minimum, maximum, and preferred size of the created component, you can
create components that grow to fill unused space or remain a fixed size, making screens more
aesthetically pleasing to your users.
Note Technically speaking, the use of Box.Filler is not limited to containers whose layout manager is
BoxLayout . You can use them anywhere you can use any other Component . The components are just invisible.
Instead of directly using the Box.Filler class, several static methods of the Box class can
help you create the appropriate filler components. The factory methods allow you to categorize
these components by type, instead of by minimum, maximum, or preferred size. You'll look at
these methods in the next two sections.
If you're interested in the class definition, it's shown next. Like the Box class, Box.Filler
isn't meant to be used as a JavaBean component.
public class Box.Filler extends Component implements Accessible {
// Constructors
public Filler(Dimension minSize, Dimension prefSize, Dimension maxSize);
// Properties
public AccessibleContext getAccessibleContext();
public Dimension getMaximumSize();
public Dimension getMinimumSize();
public Dimension getPreferredSize();
// Others
protected AccessibleContext accessibleContext;
public void changeShape(Dimension minSize, Dimension prefSize, Dimension maxSize);
}
Creating Areas That Grow
If a component has a dimensionless minimum and preferred size, and a maximum size bigger
than the screen, the component will grow to take up unused space between components in the
container along one or both axes. In the case of a Box , or more precisely, a container whose
layout manager is BoxLayout , the growth occurs along the layout manager's initially chosen
direction (either BoxLayout.X_AXIS or BoxLayout.Y_AXIS ). For a horizontal box, the growth affects
the component's width. For a vertical box, the growth is reflected in the component's height.
The name commonly given to this type of growing component is glue . The two flavors of
glue are direction-independent glue and direction-dependent glue. The following factory
methods of Box are used to create the glue components:
 
Search WWH ::




Custom Search