public class FlowLayout extends Object implements LayoutManager, Serializable
componentOrientation
属性确定,可能是一个两个值:
ComponentOrientation.LEFT_TO_RIGHT
ComponentOrientation.RIGHT_TO_LEFT
align
属性确定。可能的值是:
例如,下面的图片显示了一个使用流程布局管理器(它的默认布局管理器)来放置三个按钮的小程序:
这里是这个小程序的代码:
import java.awt.*; import java.applet.Applet; public class myButtons extends Applet { Button button1, button2, button3; public void init() { button1 = new Button("Ok"); button2 = new Button("Open"); button3 = new Button("Close"); add(button1); add(button2); add(button3); } }
一个流程布局让每个组件承担其自然(首选)的大小。
ComponentOrientation
,
Serialized Form
Modifier and Type | Field and Description |
---|---|
static int |
CENTER
此值指示每一行的组件应为中心。
|
static int |
LEADING
这个值表明,每一行的组件应该是合理的容器的方向的领先优势,例如,左到右的方向。
|
static int |
LEFT
此值指示每一行的组件应该是左对齐的。
|
static int |
RIGHT
这个值表示每一行的组件应该是正确的。
|
static int |
TRAILING
这个值表明,每一行的组件应该是合理的容器的方向的后缘,例如,在左到右方向的权利。
|
Constructor and Description |
---|
FlowLayout()
构建了以中心对齐,默认单位横向和纵向的差距的一个新的
FlowLayout 。
|
FlowLayout(int align)
构建与指定的对齐和默认单位横向和纵向的差距的一个新的
FlowLayout 。
|
FlowLayout(int align, int hgap, int vgap)
创建一个新的流布局管理器,所显示的对齐方式和所指示的水平和垂直间隙。
|
Modifier and Type | Method and Description |
---|---|
void |
addLayoutComponent(String name, Component comp)
将指定的组件添加到布局中。
|
int |
getAlignment()
获取此布局的对齐方式。
|
boolean |
getAlignOnBaseline()
如果组件要沿着它们的基线垂直对齐,则返回真值。
|
int |
getHgap()
获取组件之间的水平差距和组件之间的边界的
Container
|
int |
getVgap()
获取组件之间的垂直间隙和组件之间的边界的
Container 。
|
void |
layoutContainer(Container target)
放置容器。
|
Dimension |
minimumLayoutSize(Container target)
返回需要布局空看得见的组件包含在指定目标容器的最小尺寸。
|
Dimension |
preferredLayoutSize(Container target)
返回的首选尺寸为这种布局在指定的目标容器给空看得见的组件。
|
void |
removeLayoutComponent(Component comp)
从布局中移除指定的组件。
|
void |
setAlignment(int align)
设置此布局的对齐方式。
|
void |
setAlignOnBaseline(boolean alignOnBaseline)
设置是否组件应该沿着他们的基线垂直对齐。
|
void |
setHgap(int hgap)
设置组件之间的水平差距和组件之间的边界的
Container 。
|
void |
setVgap(int vgap)
设置组件之间的垂直间隙和组件之间的边界的
Container 。
|
String |
toString()
返回该
FlowLayout 对象及其值的字符串表示形式。
|
public static final int LEFT
public static final int CENTER
public static final int RIGHT
public static final int LEADING
Component.getComponentOrientation()
,
ComponentOrientation
,
Constant Field Values
public static final int TRAILING
Component.getComponentOrientation()
,
ComponentOrientation
,
Constant Field Values
public FlowLayout()
FlowLayout
。
public FlowLayout(int align)
FlowLayout
。的校准参数的值必须是一个
FlowLayout.LEFT
,
FlowLayout.RIGHT
,
FlowLayout.CENTER
,
FlowLayout.LEADING
,或
FlowLayout.TRAILING
。
align
的对齐值
public FlowLayout(int align, int hgap, int vgap)
的校准参数的值必须是一个FlowLayout.LEFT
,FlowLayout.RIGHT
,FlowLayout.CENTER
,FlowLayout.LEADING
,或FlowLayout.TRAILING
。
align
的对齐值
hgap
-水平差距的组件和组件之间的边界
Container
vgap
-垂直组件之间的差距和组件之间的边界的
Container
public int getAlignment()
FlowLayout.LEFT
,
FlowLayout.RIGHT
,
FlowLayout.CENTER
,
FlowLayout.LEADING
,或
FlowLayout.TRAILING
。
setAlignment(int)
public void setAlignment(int align)
FlowLayout.LEFT
FlowLayout.RIGHT
FlowLayout.CENTER
FlowLayout.LEADING
FlowLayout.TRAILING
align
之一-上面的定位值
getAlignment()
public int getHgap()
Container
Container
setHgap(int)
public void setHgap(int hgap)
Container
。
hgap
-水平差距的组件和组件之间的边界
Container
getHgap()
public int getVgap()
Container
。
Container
setVgap(int)
public void setVgap(int vgap)
Container
。
vgap
-垂直组件之间的差距和组件之间的边界的
Container
getVgap()
public void setAlignOnBaseline(boolean alignOnBaseline)
alignOnBaseline
是否元件应垂直对准他们的基线
public boolean getAlignOnBaseline()
public void addLayoutComponent(String name, Component comp)
addLayoutComponent
接口
LayoutManager
name
-组件的名称
comp
-要添加的组件
public void removeLayoutComponent(Component comp)
removeLayoutComponent
接口
LayoutManager
comp
-删除组件
Container.removeAll()
public Dimension preferredLayoutSize(Container target)
preferredLayoutSize
接口
LayoutManager
target
-需要摆放的集装箱
Container
,
minimumLayoutSize(java.awt.Container)
,
Container.getPreferredSize()
public Dimension minimumLayoutSize(Container target)
minimumLayoutSize
接口
LayoutManager
target
-需要摆放的集装箱
preferredLayoutSize(java.awt.Container)
,
Container
,
Container.doLayout()
public void layoutContainer(Container target)
FlowLayout
目标容器对象的对齐方式。
layoutContainer
接口
LayoutManager
target
-指定的组件布局
Container
,
Container.doLayout()
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.