|
JavaTM 2 Platform Std. Ed. v1.3.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.swing.BoxLayout
A layout manager that allows multiple components to be layed out either vertically or horizontally. The components will not wrap so, for example, a vertical arrangement of components will stay vertically arranged when the frame is resized.
|
Nesting multiple panels with different combinations of horizontal and vertical gives an effect similar to GridBagLayout, without the complexity. The diagram shows two panels arranged horizontally, each of which contains 3 components arranged vertically.
The Box container uses BoxLayout (unlike JPanel, which defaults to flow layout). You can nest multiple boxes and add components to them to get the arrangement you want.
The BoxLayout manager that places each of its managed components from left to right or from top to bottom. When you create a BoxLayout, you specify whether its major axis is the X axis (which means left to right placement) or Y axis (top to bottom placement). Components are arranged from left to right (or top to bottom), in the same order as they were added to the container.
Instead of using BoxLayout directly, many programs use the Box class. The Box class provides a lightweight container that uses a BoxLayout. Box also provides handy methods to help you use BoxLayout well.
BoxLayout attempts to arrange components at their preferred widths (for left to right layout) or heights (for top to bottom layout). For a left to right layout, if not all the components are the same height, BoxLayout attempts to make all the components as high as the highest component. If that's not possible for a particular component, then BoxLayout aligns that component vertically, according to the component's Y alignment. By default, a component has an Y alignment of 0.5, which means that the vertical center of the component should have the same Y coordinate as the vertical centers of other components with 0.5 Y alignment.
Similarly, for a vertical layout, BoxLayout attempts to make all components in the column as wide as the widest component; if that fails, it aligns them horizontally according to their X alignments.
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. A future release of Swing will provide support for long term persistence.
Box
,
Component.getAlignmentX()
,
Component.getAlignmentY()
, Serialized FormField Summary | |
static int |
X_AXIS
Specifies that components should be laid out left to right. |
static int |
Y_AXIS
Specifies that components should be laid out top to bottom. |
Constructor Summary | |
BoxLayout(Container target,
int axis)
Creates a layout manager that will lay out components either left to right or top to bottom, as specified in the axis parameter. |
Method Summary | |
void |
addLayoutComponent(Component comp,
Object constraints)
Not used by this class. |
void |
addLayoutComponent(String name,
Component comp)
Not used by this class. |
float |
getLayoutAlignmentX(Container target)
Returns the alignment along the X axis for the container. |
float |
getLayoutAlignmentY(Container target)
Returns the alignment along the Y axis for the container. |
void |
invalidateLayout(Container target)
Indicates that a child has changed its layout related information, and thus any cached calculations should be flushed. |
void |
layoutContainer(Container target)
Called by the AWT when the specified container needs to be laid out. |
Dimension |
maximumLayoutSize(Container target)
Returns the maximum dimensions the target container can use to lay out the components it contains. |
Dimension |
minimumLayoutSize(Container target)
Returns the minimum dimensions needed to lay out the components contained in the specified target container. |
Dimension |
preferredLayoutSize(Container target)
Returns the preferred dimensions for this layout, given the components in the specified target container. |
void |
removeLayoutComponent(Component comp)
Not used by this class. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int X_AXIS
public static final int Y_AXIS
Constructor Detail |
public BoxLayout(Container target, int axis)
axis
parameter.target
- the container that needs to be laid outaxis
- the axis to lay out components along.
For left-to-right layout,
specify BoxLayout.X_AXIS
;
for top-to-bottom layout,
specify BoxLayout.Y_AXIS
AWTError
- if the value of axis
is invalidMethod Detail |
public void invalidateLayout(Container target)
invalidateLayout
in interface LayoutManager2
target
- the affected containerAWTError
- if the target isn't the container specified to the
BoxLayout constructorpublic void addLayoutComponent(String name, Component comp)
addLayoutComponent
in interface LayoutManager
name
- the name of the componentcomp
- the componentpublic void removeLayoutComponent(Component comp)
removeLayoutComponent
in interface LayoutManager
comp
- the componentpublic void addLayoutComponent(Component comp, Object constraints)
addLayoutComponent
in interface LayoutManager2
comp
- the componentconstraints
- constraintspublic Dimension preferredLayoutSize(Container target)
preferredLayoutSize
in interface LayoutManager
target
- the container that needs to be laid outAWTError
- if the target isn't the container specified to the
BoxLayout constructorContainer
,
minimumLayoutSize(java.awt.Container)
,
maximumLayoutSize(java.awt.Container)
public Dimension minimumLayoutSize(Container target)
minimumLayoutSize
in interface LayoutManager
target
- the container that needs to be laid outAWTError
- if the target isn't the container specified to the
BoxLayout constructorpreferredLayoutSize(java.awt.Container)
,
maximumLayoutSize(java.awt.Container)
public Dimension maximumLayoutSize(Container target)
maximumLayoutSize
in interface LayoutManager2
target
- the container that needs to be laid outAWTError
- if the target isn't the container specified to the
BoxLayout constructorpreferredLayoutSize(java.awt.Container)
,
minimumLayoutSize(java.awt.Container)
public float getLayoutAlignmentX(Container target)
getLayoutAlignmentX
in interface LayoutManager2
target
- the containerAWTError
- if the target isn't the container specified to the
BoxLayout constructorpublic float getLayoutAlignmentY(Container target)
getLayoutAlignmentY
in interface LayoutManager2
target
- the containerAWTError
- if the target isn't the container specified to the
BoxLayout constructorpublic void layoutContainer(Container target)
layoutContainer
in interface LayoutManager
target
- the container to lay outAWTError
- if the target isn't the container specified to the
BoxLayout constructor
|
JavaTM 2 Platform Std. Ed. v1.3.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2001 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.