- java.lang.Object
-
- javax.swing.LayoutStyle
-
public abstract class LayoutStyle extends Object
LayoutStyle提供了有关如何定位组件的信息。 这个类主要用于可视化工具和布局管理器。 大多数开发人员不需要使用这个类。您通常不设置或创建
LayoutStyle。 而是使用静态方法getInstance来获取当前实例。- 从以下版本开始:
- 1.6
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 描述 static classLayoutStyle.ComponentPlacementComponentPlacement是可以相对于彼此放置两个组件的可能方式的列举。
-
构造方法摘要
构造方法 Constructor 描述 LayoutStyle()创建一个新的LayoutStyle。
-
方法摘要
所有方法 静态方法 接口方法 抽象方法 具体的方法 Modifier and Type 方法 描述 abstract intgetContainerGap(JComponent component, int position, Container parent)返回要放置在组件与其父项的指定边缘之间的空间量。static LayoutStylegetInstance()返回共享实例LayoutStyle。abstract intgetPreferredGap(JComponent component1, JComponent component2, LayoutStyle.ComponentPlacement type, int position, Container parent)返回两个组件之间使用的空间量。static voidsetInstance(LayoutStyle style)设置共享实例为LayoutStyle。
-
-
-
方法详细信息
-
setInstance
public static void setInstance(LayoutStyle style)
设置共享实例为LayoutStyle。 指定null结果是使用LayoutStyle从目前的LookAndFeel。- 参数
-
style-LayoutStyle,或null - 另请参见:
-
getInstance()
-
getInstance
public static LayoutStyle getInstance()
返回共享实例LayoutStyle。 如果实例尚未在指定setInstance,这将返回LayoutStyle从目前LookAndFeel。- 结果
-
共享实例为
LayoutStyle - 另请参见:
-
LookAndFeel.getLayoutStyle()
-
getPreferredGap
public abstract int getPreferredGap(JComponent component1, JComponent component2, LayoutStyle.ComponentPlacement type, int position, Container parent)
返回两个组件之间使用的空间量。 返回值表示component2相对于component1的距离。 例如,当component2垂直放置在component2component1时,以下内容将返回component2与component1之间的空间component1:int gap = getPreferredGap(component1, component2, ComponentPlacement.RELATED, SwingConstants.NORTH, parent);type参数表示两个组件之间的关系。 如果两个组件将包含在同一个父项中,并显示类似的逻辑相关项目,请使用RELATED。 如果两个组件将包含在同一个父项中,但显示逻辑上不相关的项目使用UNRELATED。 有些看起来和感觉可能不区分RELATED和UNRELATED类型。返回值不打算考虑当前的大小和位置
component2或component1。 返回值可以考虑组件的各种属性。 例如,空格可能会根据字体大小或组件的首选大小而有所不同。- 参数
-
component1-JComponentcomponent2正在放置相对于 -
component2- 正在放置JComponent -
position- 位置component2相对于component1放置; 之一SwingConstants.NORTH,SwingConstants.SOUTH,SwingConstants.EAST或SwingConstants.WEST -
type- 两个组件的放置方式 -
parent- 母公司component2; 这可能与实际的父母有所不同,可能是null - 结果
- 在两个组件之间放置的空间量
- 异常
-
NullPointerException-如果component1,component2或者type为null -
IllegalArgumentException- 如果position不是SwingConstants.NORTHSwingConstants.SOUTH,SwingConstants.EAST或SwingConstants.WEST - 从以下版本开始:
- 1.6
- 另请参见:
-
LookAndFeel.getLayoutStyle()
-
getContainerGap
public abstract int getContainerGap(JComponent component, int position, Container parent)
返回要放置在组件与其父项的指定边缘之间的空间量。- 参数
-
component-JComponent定位 -
position- 位置component正在放置相对于其父;SwingConstants.NORTHSwingConstants.SOUTH,SwingConstants.EAST或SwingConstants.WEST -
parent- 母公司component; 这可能与实际的父母不同,可能是null - 结果
- 在组件和指定边缘之间放置的空间量
- 异常
-
IllegalArgumentException- 如果position不是SwingConstants.NORTHSwingConstants.SOUTH,SwingConstants.EAST或SwingConstants.WEST
-
-