public class BoxLayout extends Object implements LayoutManager2, Serializable
|
与水平和垂直的不同组合嵌套多个面板进行了效果类似于网格包布局管理器,无需复杂。该图表显示了两个水平排列的面板,其中每一个都包含垂直排列的3个组件。
的BoxLayout经理与轴参数指定类型布局,将构建。有四种选择:
X_AXIS - Components are laid out horizontally from left to right.
Y_AXIS - Components are laid out vertically from top to bottom.
LINE_AXIS - Components are laid out the way words are laid out in a line, based on the container's ComponentOrientation property. If the container's ComponentOrientation is horizontal then components are laid out horizontally, otherwise they are laid out vertically. For horizontal orientations, if the container's ComponentOrientation is left to right then components are laid out left to right, otherwise they are laid out right to left. For vertical orientations components are always laid out from top to bottom.
PAGE_AXIS - Components are laid out the way text lines are laid out on a page, based on the container's ComponentOrientation property. If the container's ComponentOrientation is horizontal then components are laid out vertically, otherwise they are laid out horizontally. For horizontal orientations, if the container's ComponentOrientation is left to right then components are laid out left to right, otherwise they are laid out right to left. For vertical orientations components are always laid out from top to bottom.
对于所有的方向,组件被布置在相同的顺序,因为它们被添加到容器中。
BoxLayout试图在他们的首选宽度安排组件(水平布置)或高度(垂直布置)。一个平面布局,如果不是所有的组件都是一样的高度,BoxLayout试图将所有元件的最高分高。如果一个特定的组件,这是不可能的,然后对齐,垂直BoxLayout组件,根据组件的Y对准。默认情况下,一个组件有一个Y对齐0.5,这意味着该组件的垂直中心应该有相同的Y坐标为0.5 Y对齐的其他组件的垂直中心。
同样,对于垂直布局,BoxLayout试图使所有组件在列为最广泛的组件一样宽。如果失败,它根据他们的x对齐水平对齐他们。对于PAGE_AXIS
布局,水平对齐方式是基于组件的领先了。换句话说,X对齐值0意味着一个组件的左边缘,如果容器的ComponentOrientation
是左到右,这意味着右边的成分否则。
而不是直接使用BoxLayout,许多程序使用的箱类。盒类是一个轻量级容器使用BoxLayout。它还提供了方便的方法来帮助你使用BoxLayout好。将组件添加到多个嵌套框中是一个很有力量的方法来得到你想要的。
进一步的信息和例子见How to Use BoxLayout,java教程中的一部分。
警告:序列化该类的对象与以后的Swing版本不兼容。当前的序列化支持适用于短期贮藏或RMI运行相同Swing版本的应用程序之间。为1.4,为所有JavaBeans™长期存储的支持已被添加到java.beans
包。请看XMLEncoder
。
Modifier and Type | Field and Description |
---|---|
static int |
LINE_AXIS
指定组件应该放在一行文本的目标容器的
ComponentOrientation 属性确定的方向。
|
static int |
PAGE_AXIS
指定组件应放置在该线流在一个页面的目标容器的
ComponentOrientation 属性确定的方向。
|
static int |
X_AXIS
指定要将组件放置在左到右的组件中。
|
static int |
Y_AXIS
指定组件应放在顶部到底部。
|
Constructor and Description |
---|
BoxLayout(Container target, int axis)
创建一个布局管理器,该管理器将沿给定的轴布局组件。
|
Modifier and Type | Method and Description |
---|---|
void |
addLayoutComponent(Component comp, Object constraints)
不使用这个类。
|
void |
addLayoutComponent(String name, Component comp)
不使用这个类。
|
int |
getAxis()
返回用于布局组件的轴。
|
float |
getLayoutAlignmentX(Container target)
返回容器的X轴上的对齐方式。
|
float |
getLayoutAlignmentY(Container target)
返回容器的Y轴上的对齐方式。
|
Container |
getTarget()
返回使用此布局管理器的容器。
|
void |
invalidateLayout(Container target)
表示,一个孩子已经改变了它的布局相关的信息,因此,任何缓存的计算应该被刷新。
|
void |
layoutContainer(Container target)
由AWT在指定的容器需要铺设。
|
Dimension |
maximumLayoutSize(Container target)
返回目标容器可以用来放置它所包含的组件的最大尺寸。
|
Dimension |
minimumLayoutSize(Container target)
返回指定目标容器中包含的组件所需的最小尺寸。
|
Dimension |
preferredLayoutSize(Container target)
返回此布局的首选尺寸,给定指定目标容器中的组件。
|
void |
removeLayoutComponent(Component comp)
不使用这个类。
|
public static final int X_AXIS
public static final int Y_AXIS
public static final int LINE_AXIS
ComponentOrientation
属性确定的方向。
public static final int PAGE_AXIS
ComponentOrientation
属性确定的方向。
@ConstructorProperties(value={"target","axis"}) public BoxLayout(Container target, int axis)
target
-需要摆放的集装箱
axis
-轴布置组件。可以是:
BoxLayout.X_AXIS
,
BoxLayout.Y_AXIS
,
BoxLayout.LINE_AXIS
或
BoxLayout.PAGE_AXIS
AWTError
-如果
axis
值无效
public final Container getTarget()
public final int getAxis()
BoxLayout.X_AXIS
,
BoxLayout.Y_AXIS
,
BoxLayout.LINE_AXIS
或
BoxLayout.PAGE_AXIS
public void invalidateLayout(Container target)
这种方法被称为AWT当无效的方法是在容器。因为Invalidate方法可称为异步事件线程,这个方法可以异步调用。
invalidateLayout
接口
LayoutManager2
target
-受影响的容器
AWTError
-如果目标不是指定给BoxLayout构造函数的容器
public void addLayoutComponent(String name, Component comp)
addLayoutComponent
接口
LayoutManager
name
-组件的名称
comp
-组件
public void removeLayoutComponent(Component comp)
removeLayoutComponent
接口
LayoutManager
comp
-组件
public void addLayoutComponent(Component comp, Object constraints)
addLayoutComponent
接口
LayoutManager2
comp
-组件
constraints
约束
public Dimension preferredLayoutSize(Container target)
preferredLayoutSize
接口
LayoutManager
target
-需要摆放的集装箱
AWTError
-如果目标不是指定给BoxLayout构造函数的容器
Container
,
minimumLayoutSize(java.awt.Container)
,
maximumLayoutSize(java.awt.Container)
public Dimension minimumLayoutSize(Container target)
minimumLayoutSize
接口
LayoutManager
target
-需要摆放的集装箱
AWTError
-如果目标不是指定给BoxLayout构造函数的容器
preferredLayoutSize(java.awt.Container)
,
maximumLayoutSize(java.awt.Container)
public Dimension maximumLayoutSize(Container target)
maximumLayoutSize
接口
LayoutManager2
target
-需要摆放的集装箱
AWTError
-如果目标不是指定给BoxLayout构造函数的容器
preferredLayoutSize(java.awt.Container)
,
minimumLayoutSize(java.awt.Container)
public float getLayoutAlignmentX(Container target)
getLayoutAlignmentX
接口
LayoutManager2
target
-容器
AWTError
-如果目标不是指定给BoxLayout构造函数的容器
public float getLayoutAlignmentY(Container target)
getLayoutAlignmentY
接口
LayoutManager2
target
-容器
AWTError
-如果目标不是指定给BoxLayout构造函数的容器
public void layoutContainer(Container target)
layoutContainer
接口
LayoutManager
target
-容器设计
AWTError
-如果目标不是指定给BoxLayout构造函数的容器
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.