java.lang.Object
javax.swing.LayoutStyle
LayoutStyle 提供有关如何定位组件的信息。此类主要用于可视化工具和布局管理器。大多数开发人员不需要使用此类。
您通常不会设置或创建 LayoutStyle 。而是使用静态方法 getInstance 来获取当前实例。
- 自从:
- 1.6
-
内部类总结
内部类 -
构造方法总结
构造方法 -
方法总结
修饰符和类型方法描述abstract 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的共享实例。
-
构造方法详细信息
-
LayoutStyle
public LayoutStyle()创建一个新的LayoutStyle。您通常不会创建LayoutStyle。而是使用方法getInstance来获取当前的LayoutStyle。
-
-
方法详情
-
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) 返回两个组件之间使用的空间量。返回值表示放置component2相对于component1的距离。例如,当component2垂直放置在component1上方时,以下返回放置在component2和component1之间的空间量:int gap = getPreferredGap(component1, component2, ComponentPlacement.RELATED, SwingConstants.NORTH, parent);type参数指示两个组件之间的关系。如果这两个组件将包含在同一个父级中并且显示相似的逻辑相关项目,请使用RELATED。如果这两个组件将包含在同一个父组件中但显示逻辑上不相关的项目,请使用UNRELATED。有些外观可能无法区分RELATED和UNRELATED类型。返回值不考虑
component2或component1的当前大小和位置。返回值可以考虑组件的各种属性。例如,空间可能会根据字体大小或组件的首选大小而有所不同。- 参数:
component1-JComponentcomponent2相对于component2- 被放置的JComponenttype- 如何放置两个组件position- 位置component2相对于component1放置;SwingConstants.NORTH、SwingConstants.SOUTH、SwingConstants.EAST或SwingConstants.WEST之一parent-component2的父级;这可能与实际父级不同,它可能是null- 返回:
- 放置在两个组件之间的空间量
- 抛出:
NullPointerException- 如果component1、component2或type是nullIllegalArgumentException- 如果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之一
-