java.lang.Object
java.awt.CardLayout
- 所有已实现的接口:
-
LayoutManager,LayoutManager2,Serializable
CardLayout对象是容器的布局管理器。它将容器中的每个组件视为一张卡片。一次只有一张卡片可见,并且容器充当卡片堆栈。将组件添加到CardLayout对象时,第一个组件是容器首次显示时可见的组件。
卡片的顺序由容器自身组件对象的内部顺序确定。CardLayout定义了一组方法,允许应用程序按顺序翻转这些卡片,或显示指定的卡片。可以使用addLayoutComponent(java.awt.Component, java.lang.Object)方法将给定卡片与字符串标识符关联起来,以便快速随机访问。
- 自:
- 1.0
- 参见:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLayoutComponent(Component comp, Object constraints) 将指定的组件添加到此卡片布局的内部名称表中。voidaddLayoutComponent(String name, Component comp) 已弃用。void翻转到容器的第一张卡片。intgetHgap()获取组件之间的水平间距。floatgetLayoutAlignmentX(Container parent) 返回沿x轴的对齐方式。floatgetLayoutAlignmentY(Container parent) 返回沿y轴的对齐方式。intgetVgap()获取组件之间的垂直间距。voidinvalidateLayout(Container target) 使布局失效,表示如果布局管理器缓存了信息,则应丢弃该信息。void翻转到容器的最后一张卡片。voidlayoutContainer(Container parent) 使用此卡片布局对指定的容器进行布局。maximumLayoutSize(Container target) 返回给定目标容器中组件的此布局的最大尺寸。minimumLayoutSize(Container parent) 计算指定面板的最小尺寸。void翻转到指定容器的下一张卡片。preferredLayoutSize(Container parent) 使用此卡片布局确定容器参数的首选大小。void翻转到指定容器的上一张卡片。void从布局中移除指定的组件。voidsetHgap(int hgap) 设置组件之间的水平间距。voidsetVgap(int vgap) 设置组件之间的垂直间距。void翻转到使用指定name添加到此布局的组件,使用addLayoutComponent。toString()返回此卡片布局状态的字符串表示形式。
-
Constructor Details
-
CardLayout
public CardLayout()创建一个新的卡片布局,间隙大小为零。 -
CardLayout
public CardLayout(int hgap, int vgap) 创建一个具有指定水平和垂直间隙的新卡片布局。水平间隙放置在左右边缘。垂直间隙放置在顶部和底部边缘。- 参数:
-
hgap- 水平间距。 -
vgap- 垂直间距。
-
-
Method Details
-
getHgap
public int getHgap()获取组件之间的水平间距。- 返回:
- 组件之间的水平间距。
- 自:
- 1.1
- 参见:
-
setHgap
public void setHgap(int hgap) 设置组件之间的水平间距。- 参数:
-
hgap- 组件之间的水平间距。 - 自:
- 1.1
- 参见:
-
getVgap
public int getVgap()获取组件之间的垂直间距。- 返回:
- 组件之间的垂直间距。
- 参见:
-
setVgap
public void setVgap(int vgap) 设置组件之间的垂直间距。- 参数:
-
vgap- 组件之间的垂直间距。 - 自:
- 1.1
- 参见:
-
addLayoutComponent
将指定的组件添加到此卡片布局的内部名称表中。由constraints指定的对象必须是一个字符串。卡片布局将此字符串存储为可以用于随机访问特定卡片的键值对。通过调用show方法,应用程序可以显示具有指定名称的组件。- 指定者:
-
addLayoutComponent在接口LayoutManager2中 - 参数:
-
comp- 要添加的组件。 -
constraints- 标识布局中特定卡片的标签。 - 抛出:
-
IllegalArgumentException- 如果约束不是字符串。 - 参见:
-
addLayoutComponent
Deprecated.replaced byaddLayoutComponent(Component, Object).从接口复制的描述:LayoutManager如果布局管理器使用每个组件的字符串,将组件comp添加到布局中,并将其与name指定的字符串关联起来。- 指定者:
-
addLayoutComponent在接口LayoutManager中 - 参数:
-
name- 与组件关联的字符串 -
comp- 要添加的组件
-
removeLayoutComponent
从布局中移除指定的组件。如果卡片在顶部可见,则显示其下面的下一张卡片。- 指定者:
-
removeLayoutComponent在接口LayoutManager中 - 参数:
-
comp- 要移除的组件。 - 参见:
-
preferredLayoutSize
使用此卡片布局确定容器参数的首选大小。- 指定者:
-
preferredLayoutSize在接口LayoutManager中 - 参数:
-
parent- 要进行布局的父容器 - 返回:
- 用于布局指定容器的子组件的首选尺寸
- 参见:
-
minimumLayoutSize
计算指定面板的最小尺寸。- 指定者:
-
minimumLayoutSize在接口LayoutManager中 - 参数:
-
parent- 要进行布局的父容器 - 返回:
- 布局指定容器的子组件所需的最小尺寸
- 参见:
-
maximumLayoutSize
返回给定目标容器中组件的此布局的最大尺寸。- 指定者:
-
maximumLayoutSize在接口LayoutManager2中 - 参数:
-
target- 需要进行布局的组件 - 返回:
- 容器的最大尺寸
- 参见:
-
getLayoutAlignmentX
返回沿x轴的对齐方式。这指定组件希望相对于其他组件对齐的方式。该值应为0到1之间的数字,其中0表示沿原点对齐,1表示与原点最远的对齐,0.5表示居中,依此类推。- 指定由:
-
getLayoutAlignmentX在接口LayoutManager2中 - 参数:
-
parent- 目标容器 - 返回:
- x轴对齐偏好
-
getLayoutAlignmentY
返回沿y轴的对齐方式。这指定组件希望相对于其他组件对齐的方式。该值应为介于0和1之间的数字,其中0表示沿原点对齐,1表示与原点最远对齐,0.5表示居中,依此类推。- 指定由:
-
getLayoutAlignmentY在接口LayoutManager2中 - 参数:
-
parent- 目标容器 - 返回:
- y轴对齐偏好
-
invalidateLayout
使布局失效,表示如果布局管理器缓存了信息,则应丢弃该信息。- 指定由:
-
invalidateLayout在接口LayoutManager2中 - 参数:
-
target- 目标容器
-
layoutContainer
使用此卡片布局对指定的容器进行布局。父容器中的每个组件都会被重新调整为容器的大小,减去周围插入的空间、水平间隙和垂直间隙。
- 指定由:
-
layoutContainer在接口LayoutManager中 - 参数:
-
parent- 要进行布局的父容器 - 参见:
-
first
翻转到容器的第一张卡片。- 参数:
-
parent- 要进行布局的父容器 - 参见:
-
next
翻转到指定容器的下一张卡片。如果当前可见的卡片是最后一张,则此方法将翻转到布局中的第一张卡片。- 参数:
-
parent- 要进行布局的父容器 - 参见:
-
previous
翻转到指定容器的上一张卡片。如果当前可见的卡片是第一张,则此方法将翻转到布局中的最后一张卡片。- 参数:
-
parent- 要进行布局的父容器 - 参见:
-
last
翻转到容器的最后一张卡片。- 参数:
-
parent- 要进行布局的父容器 - 参见:
-
show
翻转到使用指定name添加到此布局的组件,使用addLayoutComponent。如果不存在这样的组件,则不会发生任何操作。- 参数:
-
parent- 要进行布局的父容器 -
name- 组件名称 - 参见:
-
toString
返回此卡片布局状态的字符串表示形式。
-
addLayoutComponent(Component, Object)取代。