java.lang.Object
javax.swing.LayoutStyle
LayoutStyle 提供有关如何定位组件的信息。此类主要适用于可视化工具和布局管理器。大多数开发人员不需要使用此类。
通常情况下,您不会设置或创建 LayoutStyle。而是使用静态方法 getInstance 来获取当前实例。
- 自版本:
- 1.6
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumComponentPlacement是两个组件相对放置的可能方式的枚举。 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract intgetContainerGap(JComponent component, int position, Container parent) 返回要放置在组件和其父级指定边缘之间的空间量。static LayoutStyle返回LayoutStyle的共享实例。abstract intgetPreferredGap(JComponent component1, JComponent component2, LayoutStyle.ComponentPlacement type, int position, Container parent) 返回两个组件之间要使用的空间量。static voidsetInstance(LayoutStyle style) 设置LayoutStyle的共享实例。
-
Constructor Details
-
LayoutStyle
public LayoutStyle()创建一个新的LayoutStyle。通常情况下,您不会创建LayoutStyle。而是使用方法getInstance来获取当前的LayoutStyle。
-
-
Method Details
-
setInstance
设置LayoutStyle的共享实例。指定null将使用当前LookAndFeel中的LayoutStyle。- 参数:
-
style-LayoutStyle,或null - 参见:
-
getInstance
返回LayoutStyle的共享实例。如果在setInstance中未指定实例,则将返回当前LookAndFeel中的LayoutStyle。- 返回:
-
LayoutStyle的共享实例 - 参见:
-
getPreferredGap
public abstract int getPreferredGap(JComponent component1, JComponent component2, LayoutStyle.ComponentPlacement type, int position, Container parent) 返回两个组件之间要使用的空间量。返回值指示要相对于component1放置component2的距离。例如,以下示例返回在将component2垂直放置在component1之上时,要放置在component2和component1之间的空间量:int gap = getPreferredGap(component1, component2, ComponentPlacement.RELATED, SwingConstants.NORTH, parent);type参数指示两个组件之间的关系。如果两个组件将包含在同一个父级中,并显示类似逻辑相关的项目,请使用RELATED。如果两个组件将包含在同一个父级中,但显示逻辑上不相关的项目,请使用UNRELATED。某些外观可能不区分RELATED和UNRELATED类型。返回值不打算考虑
component2或component1的当前大小和位置。返回值可能会考虑组件的各种属性。例如,空间可能会根据字体大小或组件的首选大小而变化。- 参数:
-
component1- 要相对放置component2的JComponent -
component2- 要放置的JComponent -
type- 两个组件的放置方式 -
position-component2相对于component1被放置的位置;其中之一为SwingConstants.NORTH、SwingConstants.SOUTH、SwingConstants.EAST或SwingConstants.WEST -
parent-component2的父级;这可能与实际父级不同,也可能为null - 返回:
- 两个组件之间要放置的空间量
- 抛出:
-
NullPointerException- 如果component1、component2或type为null -
IllegalArgumentException- 如果position不是SwingConstants.NORTH、SwingConstants.SOUTH、SwingConstants.EAST或SwingConstants.WEST之一 - 自版本:
- 1.6
- 参见:
-
getContainerGap
返回要放置在组件和其父级指定边缘之间的空间量。- 参数:
-
component- 要定位的JComponent -
position-component相对于其父级被放置的位置;其中之一为SwingConstants.NORTH、SwingConstants.SOUTH、SwingConstants.EAST或SwingConstants.WEST -
parent-component的父级;这可能与实际父级不同,也可能为null - 返回:
- 要放置在组件和指定边缘之间的空间量
- 抛出:
-
IllegalArgumentException- 如果position不是SwingConstants.NORTH、SwingConstants.SOUTH、SwingConstants.EAST或SwingConstants.WEST之一
-