|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.Box
public class Box
使用 BoxLayout 对象作为其布局管理器的一个轻量级容器。Box 提供几个对使用 BoxLayout 的容器(甚至非 Box 容器)有用的类方法。
Box 类可以创建几种影响布局的不可见组件:glue、struts 和 rigid 区域。如果 Box 包含的所有组件都有一个固定大小,可以使用 glue 组件(由 createGlue 返回)来控制组件的位置。如果想让两个组件之间有一个固定的空间量,可以尝试使用 strut(createHorizontalStrut 或 createVerticalStrut)。如果需要一个总是占用相同空间量的不可见组件,可以通过调用 createRigidArea 获得。
如果要实现一个 BoxLayout,可以在 The Java Tutorial 的 How to Use BoxLayout 一节中获得更多信息和示例。
警告:此类的已序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储,或适用于在运行相同 Swing 版本的应用程序之间进行 RMI(Remote Method Invocation,远程方法调用)。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder。
BoxLayout| 嵌套类摘要 | |
|---|---|
protected class |
Box.AccessibleBox
此类实现 Box 类的可访问性支持。 |
static class |
Box.Filler
参与布局但没有视图的轻量级组件的实现。 |
| 从类 javax.swing.JComponent 继承的嵌套类/接口 |
|---|
JComponent.AccessibleJComponent |
| 从类 java.awt.Container 继承的嵌套类/接口 |
|---|
Container.AccessibleAWTContainer |
| 从类 java.awt.Component 继承的嵌套类/接口 |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| 字段摘要 |
|---|
| 从类 javax.swing.JComponent 继承的字段 |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| 从类 java.awt.Component 继承的字段 |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| 从接口 java.awt.image.ImageObserver 继承的字段 |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| 构造方法摘要 | |
|---|---|
Box(int axis)
创建一个沿指定坐标轴显示其组件的 Box。 |
|
| 方法摘要 | |
|---|---|
static Component |
createGlue()
创建一个不可见的 "glue" 组件,其可见组件有一个最大宽度(对于横向 box)或高度(对于纵向 box)的 Box,该组件可能很有用。 |
static Box |
createHorizontalBox()
创建一个从左到右显示其组件的 Box。 |
static Component |
createHorizontalGlue()
创建一个横向 glue 组件。 |
static Component |
createHorizontalStrut(int width)
创建一个不可见的、固定宽度的组件。 |
static Component |
createRigidArea(Dimension d)
创建一个总是具有指定大小的不可见组件。 |
static Box |
createVerticalBox()
创建一个从上到下显示其组件的 Box。 |
static Component |
createVerticalGlue()
创建一个纵向 glue 组件。 |
static Component |
createVerticalStrut(int height)
创建一个不可见的、固定高度的组件。 |
AccessibleContext |
getAccessibleContext()
获取与此 Box 相关联的 AccessibleContext。 |
protected void |
paintComponent(Graphics g)
绘制此 Box。 |
void |
setLayout(LayoutManager l)
抛出一个 AWTError,因为 Box 只能使用 BoxLayout。 |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| 构造方法详细信息 |
|---|
public Box(int axis)
Box。
axis - 可以是 BoxLayout.X_AXIS、BoxLayout.Y_AXIS、BoxLayout.LINE_AXIS 或 BoxLayout.PAGE_AXIS。
AWTError - 如果 axis 无效createHorizontalBox(),
createVerticalBox()| 方法详细信息 |
|---|
public static Box createHorizontalBox()
Box。如果想创建一个遵守该组件方向的 Box,则应使用构造方法并传入 BoxLayout.LINE_AXIS 来创建 Box,例如:
Box lineBox = new Box(BoxLayout.LINE_AXIS);
public static Box createVerticalBox()
Box。如果想创建一个遵守该组件方向的 Box,则应使用构造方法并传入 BoxLayout.PAGE_AXIS 来创建 Box,例如:
Box lineBox = new Box(BoxLayout.PAGE_AXIS);
public static Component createRigidArea(Dimension d)
d - 不可见组件的尺寸
createGlue(),
createHorizontalStrut(int),
createVerticalStrut(int)public static Component createHorizontalStrut(int width)
width - 不可见组件的宽度,以像素为单位,该宽度 >= 0
createVerticalStrut(int),
createGlue(),
createRigidArea(java.awt.Dimension)public static Component createVerticalStrut(int height)
height - 不可见组件的高度,以像素为单位,该高度 >= 0
createHorizontalStrut(int),
createGlue(),
createRigidArea(java.awt.Dimension)public static Component createGlue()
例如,假定有一个包含两个固定大小组件的横向 box。如果 box 获得额外的空间,而这两个固定大小的组件不会变得更大,那么额外的空间放到哪去呢?在没有 glue 的情况下,额外的空间将放到第二个组件的右边。如果将 glue 放在两个固定大小组件之间,则额外的空间将放到那里。如果将 glue 放在第一个固定大小组件的前面,则额外的空间将放到那里,两个固定大小的组件将被挤到 box 的右边缘。如果将 glue 放在第一个固定大小组件之前,第二个固定大小组件之后,则这两个固定大小组件将被挤到 box 的中心。
要使用 glue,请调用 Box.createGlue,并将返回的组件添加到容器中。glue 组件没有最小大小或首选大小,因此只有剩余的空间可用时,它才占用空间。如果剩余的空间可用,那么就像其他任何没有最大宽度或高度的组件一样,glue 组件将占用其可用的共享横向或纵向空间。
public static Component createHorizontalGlue()
public static Component createVerticalGlue()
public void setLayout(LayoutManager l)
Container 中的 setLayoutl - 要使用的布局管理器Container.doLayout(),
Container.getLayout()protected void paintComponent(Graphics g)
Box。如果此 Box 具有一个 UI,则此方法调用 super 的实现,否则,如果此 Box 是不透明的,则使用背景填充 Graphics。
JComponent 中的 paintComponentg - 要绘制的 Graphics
NullPointerException - 如果 g 为 nullJComponent.paint(java.awt.Graphics),
ComponentUIpublic AccessibleContext getAccessibleContext()
Accessible 中的 getAccessibleContextJComponent 中的 getAccessibleContext
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。