JavaTM 2 Platform
Standard Ed. 6

javax.swing
类 LayoutStyle

java.lang.Object
  继承者 javax.swing.LayoutStyle

public abstract class LayoutStyle
extends Object

LayoutStyle 提供有关如何确定组件位置的信息。此类主要用于可视化工具和布局管理器。大多数开发人员不需要使用此类。

通常不设置或创建 LayoutStyle。而是使用静态方法 getInstance 获取当前实例。

从以下版本开始:
1.6

嵌套类摘要
static class LayoutStyle.ComponentPlacement
          ComponentPlacement 是两个组件相对于彼此的可能放置方式的枚举。
 
构造方法摘要
LayoutStyle()
          创建一个新的 LayoutStyle
 
方法摘要
abstract  int getContainerGap(JComponent component, int position, Container parent)
          返回组件与其父容器的指定边缘之间放置的空格数量。
static LayoutStyle getInstance()
          返回 LayoutStyle 的共享实例。
abstract  int getPreferredGap(JComponent component1, JComponent component2, LayoutStyle.ComponentPlacement type, int position, Container parent)
          返回两个组件之间使用的空格的数量。
static void setInstance(LayoutStyle style)
          设置 LayoutStyle 的共享实例。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

LayoutStyle

public LayoutStyle()
创建一个新的 LayoutStyle。通常不创建 LayoutStyle。而是使用 getInstance 方法获取当前 LayoutStyle

方法详细信息

setInstance

public static void setInstance(LayoutStyle style)
设置 LayoutStyle 的共享实例。指定 null 将导致使用当前 LookAndFeelLayoutStyle

参数:
style - LayoutStyle,或 null
另请参见:
getInstance()

getInstance

public static LayoutStyle getInstance()
返回 LayoutStyle 的共享实例。如果没有在 setInstance 中指定实例,则此方法将返回当前 LookAndFeelLayoutStyle

返回:
LayoutStyle 的共享实例
另请参见:
LookAndFeel.getLayoutStyle()

getPreferredGap

public abstract int getPreferredGap(JComponent component1,
                                    JComponent component2,
                                    LayoutStyle.ComponentPlacement type,
                                    int position,
                                    Container parent)
返回两个组件之间使用的空格的数量。返回值表示相对于 component1 放置 component2 的距离。例如,当 component2 被放置在 component1 的正上方时,以下代码返回 component2component1 之间放置的空格数:
int gap = getPreferredGap(component1, component2,
ComponentPlacement.RELATED,
SwingConstants.NORTH, parent);
 
type 参数指示两个组件之间的关系。如果这两个组件将被包含在同一个父容器中并显示相似的逻辑相关项,则使用 RELATED。如果这两个组件将被包含在同一个父容器中但显示逻辑不相关项,则使用 UNRELATED。某些外观不区分 RELATEDUNRELATED 类型。

返回值不考虑 component2component1 的当前大小和位置。返回值可能考虑组件的各种属性。例如,空格可能随字体大小或组件首选大小的不同而不同。

参数:
component1 - JComponentcomponent2 将相对于该 JComponent 被放置
component2 - 将被放置的 JComponent
position - component2 将相对于 component1 进行放置的位置;SwingConstants.NORTHSwingConstants.SOUTHSwingConstants.EASTSwingConstants.WEST 之一
type - 这两个组件将如何放置
parent - component2 的父容器;它可能不同于实际的父容器,可能为 null
返回:
两个组件之间放置的空格数量
抛出:
NullPointerException - 如果 component1component2typenull
IllegalArgumentException - 如果 position 不是 SwingConstants.NORTHSwingConstants.SOUTHSwingConstants.EASTSwingConstants.WEST 之一
从以下版本开始:
1.6
另请参见:
LookAndFeel.getLayoutStyle()

getContainerGap

public abstract int getContainerGap(JComponent component,
                                    int position,
                                    Container parent)
返回组件与其父容器的指定边缘之间放置的空格数量。

参数:
component - 要放置的 JComponent
position - component 将相对于其父容器被放置的位置;SwingConstants.NORTHSwingConstants.SOUTHSwingConstants.EASTSwingConstants.WEST 之一
parent - component 的父容器;它可能不同于实际的父容器,可能为 null
返回:
组件与指定边缘之间放置的空格数
抛出:
IllegalArgumentException - 如果 position 不是 SwingConstants.NORTHSwingConstants.SOUTHSwingConstants.EASTSwingConstants.WEST 之一

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java 2 SDK SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策