模块 java.desktop

类 LayoutStyle

java.lang.Object
javax.swing.LayoutStyle

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

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

自从:
1.6
  • 构造方法详细信息

    • LayoutStyle

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

    • setInstance

      public static void setInstance(LayoutStyle  style)
      设置 LayoutStyle 的共享实例。指定 null 会导致使用当前 LookAndFeel 中的 LayoutStyle
      参数:
      style - LayoutStylenull
      参见:
    • getInstance

      public static LayoutStyle  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 上方时,以下返回放置在 component2component1 之间的空间量:
        int gap = getPreferredGap(component1, component2,
                     ComponentPlacement.RELATED,
                     SwingConstants.NORTH, parent);
       
      type 参数指示两个组件之间的关系。如果这两个组件将包含在同一个父级中并且显示相似的逻辑相关项目,请使用 RELATED 。如果这两个组件将包含在同一个父组件中但显示逻辑上不相关的项目,请使用 UNRELATED 。有些外观可能无法区分 RELATEDUNRELATED 类型。

      返回值不考虑 component2component1 的当前大小和位置。返回值可以考虑组件的各种属性。例如,空间可能会根据字体大小或组件的首选大小而有所不同。

      参数:
      component1 - JComponent component2 相对于
      component2 - 被放置的 JComponent
      type - 如何放置两个组件
      position - 位置 component2 相对于 component1 放置; SwingConstants.NORTHSwingConstants.SOUTHSwingConstants.EASTSwingConstants.WEST 之一
      parent - component2 的父级;这可能与实际父级不同,它可能是 null
      返回:
      放置在两个组件之间的空间量
      抛出:
      NullPointerException - 如果 component1component2typenull
      IllegalArgumentException - 如果 position 不是 SwingConstants.NORTHSwingConstants.SOUTHSwingConstants.EASTSwingConstants.WEST 之一
      自从:
      1.6
      参见:
    • 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 之一