模块 java.desktop

类 JSplitPane

所有已实现的接口:
ImageObserver , MenuContainer , Serializable , Accessible

@JavaBean (defaultProperty ="UI") public class JSplitPane extends JComponent implements Accessible
JSplitPane 用于划分两个(并且只有两个)Component s。两个 Component 基于外观实现以图形方式划分,然后用户可以交互式地调整两个 Component 的大小。有关使用 JSplitPane 的信息在 The Java Tutorial如何使用拆分窗格 中。

拆分窗格中的两个 Component 可以使用 JSplitPane.HORIZONTAL_SPLIT 从左到右对齐,或者使用 JSplitPane.VERTICAL_SPLIT 从上到下对齐。更改 Component 大小的首选方法是调用 setDividerLocation,其中 location 是新的 x 或 y 位置,具体取决于 JSplitPane 的方向。

要将 Component 调整为首选大小,请调用 resetToPreferredSizes

当用户调整 Component 的大小时,Components 的最小尺寸用于确定 Component 可以设置的最大/最小位置。如果两个组件的最小尺寸大于拆分窗格的尺寸,则分隔线将不允许您调整它的大小。要更改 JComponent 的最小大小,请参阅 JComponent.setMinimumSize(java.awt.Dimension)

当用户调整拆分窗格大小时,新空间会根据 resizeWeight 属性在两个组件之间分配。默认值 0 表示右/底部组件获得所有空间,而值 1 表示左/顶部组件获得所有空间。

Warning: Swing 不是线程安全的。有关详细信息,请参阅 Swing 的线程策略

Warning: 此类的序列化对象将与未来的 Swing 版本不兼容。当前的序列化支持适用于运行相同版本 Swing 的应用程序之间的短期存储或 RMI。从 1.4 开始,对所有 JavaBeans 的长期存储的支持已添加到 java.beans 包中。请参阅 XMLEncoder

自从:
1.2
参见:
  • 字段详细信息

    • VERTICAL_SPLIT

      public static final int VERTICAL_SPLIT
      垂直分割表示 Component 沿 y 轴分割。例如,两个 Component 将被拆分为一个放在另一个之上。
      参见:
    • HORIZONTAL_SPLIT

      public static final int HORIZONTAL_SPLIT
      水平分割表示 Component 沿 x 轴分割。例如,两个 Component 将被拆分到另一个的左侧。
      参见:
    • LEFT

      public static final String  LEFT
      用于将一个 Component 添加到另一个 Component 的左侧。
      参见:
    • TOP

      public static final String  TOP
      用于在另一个 Component 之上添加一个 Component
      参见:
    • BOTTOM

      public static final String  BOTTOM
      用于在另一个 Component 下面添加一个 Component
      参见:
    • DIVIDER

      public static final String  DIVIDER
      用于添加代表分频器的 Component
      参见:
    • ORIENTATION_PROPERTY

      public static final String  ORIENTATION_PROPERTY
      方向(水平或垂直)的绑定属性名称。
      参见:
    • CONTINUOUS_LAYOUT_PROPERTY

      public static final String  CONTINUOUS_LAYOUT_PROPERTY
      continuousLayout 的绑定属性名称。
      参见:
    • DIVIDER_SIZE_PROPERTY

      public static final String  DIVIDER_SIZE_PROPERTY
      边框的绑定属性名称。
      参见:
    • ONE_TOUCH_EXPANDABLE_PROPERTY

      public static final String  ONE_TOUCH_EXPANDABLE_PROPERTY
      oneTouchExpandable 的绑定属性。
      参见:
    • LAST_DIVIDER_LOCATION_PROPERTY

      public static final String  LAST_DIVIDER_LOCATION_PROPERTY
      lastLocation 的绑定属性。
      参见:
    • DIVIDER_LOCATION_PROPERTY

      public static final String  DIVIDER_LOCATION_PROPERTY
      dividerLocation 的绑定属性。
      自从:
      1.3
      参见:
    • RESIZE_WEIGHT_PROPERTY

      public static final String  RESIZE_WEIGHT_PROPERTY
      重量的绑定属性。
      自从:
      1.3
      参见:
    • orientation

      protected int orientation
      意见如何分裂。
    • continuousLayout

      protected boolean continuousLayout
      调整大小时是否不断重新显示视图。
    • leftComponent

      protected Component  leftComponent
      左侧或顶部组件。
    • rightComponent

      protected Component  rightComponent
      右侧或底部组件。
    • dividerSize

      protected int dividerSize
      分隔线的大小。
    • oneTouchExpandable

      protected boolean oneTouchExpandable
      是否提供了一个小部件来快速展开/折叠拆分窗格?
    • lastDividerLocation

      protected int lastDividerLocation
      拆分窗格的先前位置。
  • 构造方法详细信息

    • JSplitPane

      public JSplitPane()
      创建一个新的 JSplitPane 配置为水平并排排列子组件,使用组件的两个按钮。
    • JSplitPane

      @ConstructorProperties ("orientation") public JSplitPane(int newOrientation)
      创建一个配置有指定方向的新 JSplitPane
      参数:
      newOrientation - JSplitPane.HORIZONTAL_SPLITJSplitPane.VERTICAL_SPLIT
      抛出:
      IllegalArgumentException - 如果 orientation 不是 HORIZONTAL_SPLIT 或 VERTICAL_SPLIT 之一。
    • JSplitPane

      public JSplitPane(int newOrientation, boolean newContinuousLayout)
      创建具有指定方向和重绘样式的新 JSplitPane
      参数:
      newOrientation - JSplitPane.HORIZONTAL_SPLITJSplitPane.VERTICAL_SPLIT
      newContinuousLayout - 一个boolean,true 表示组件随着分隔线改变位置而连续重绘,false 表示等待分隔线位置停止改变才重绘
      抛出:
      IllegalArgumentException - 如果 orientation 不是 HORIZONTAL_SPLIT 或 VERTICAL_SPLIT 之一
    • JSplitPane

      public JSplitPane(int newOrientation, Component  newLeftComponent, Component  newRightComponent)
      创建具有指定方向和指定组件的新 JSplitPane
      参数:
      newOrientation - JSplitPane.HORIZONTAL_SPLITJSplitPane.VERTICAL_SPLIT
      newLeftComponent - 将出现在水平拆分窗格左侧或垂直拆分窗格顶部的 Component
      newRightComponent - 将出现在水平拆分窗格右侧或垂直拆分窗格底部的 Component
      抛出:
      IllegalArgumentException - 如果 orientation 不是以下之一:HORIZONTAL_SPLIT 或 VERTICAL_SPLIT
    • JSplitPane

      public JSplitPane(int newOrientation, boolean newContinuousLayout, Component  newLeftComponent, Component  newRightComponent)
      创建具有指定方向和重绘样式以及指定组件的新 JSplitPane
      参数:
      newOrientation - JSplitPane.HORIZONTAL_SPLITJSplitPane.VERTICAL_SPLIT
      newContinuousLayout - 一个boolean,true 表示组件随着分隔线改变位置而连续重绘,false 表示等待分隔线位置停止改变才重绘
      newLeftComponent - 将出现在水平拆分窗格左侧或垂直拆分窗格顶部的 Component
      newRightComponent - 将出现在水平拆分窗格右侧或垂直拆分窗格底部的 Component
      抛出:
      IllegalArgumentException - 如果 orientation 不是 HORIZONTAL_SPLIT 或 VERTICAL_SPLIT 之一
  • 方法详情

    • setUI

      public void setUI(SplitPaneUI  ui)
      设置呈现此组件的 L&F 对象。
      参数:
      ui - SplitPaneUI L&F 对象
      参见:
    • getUI

      @BeanProperty (bound =false, expert =true, description ="The L&F object that renders this component.") public SplitPaneUI  getUI()
      返回提供当前外观的 SplitPaneUI
      重写:
      getUI 在类 JComponent
      返回:
      呈现此组件的 SplitPaneUI 对象
    • updateUI

      public void updateUI()
      来自 UIManager 的通知,L&F 已更改。用 UIManager 的最新版本替换当前 UI 对象。
      重写:
      updateUI 在类 JComponent
      参见:
    • getUIClassID

      @BeanProperty (bound =false, expert =true, description ="A string that specifies the name of the L&F class.") public String  getUIClassID()
      返回呈现此组件的 L&F 类的名称。
      重写:
      getUIClassID 在类 JComponent
      返回:
      字符串“SplitPaneUI”
      参见:
    • setDividerSize

      @BeanProperty (description ="The size of the divider.") public void setDividerSize(int newSize)
      设置分隔线的大小。分隔符大小 newSize < 0 将被忽略。
      参数:
      newSize - 一个整数,以像素为单位给出分隔符的大小
    • getDividerSize

      public int getDividerSize()
      返回分隔符的大小。
      返回:
      一个整数,以像素为单位给出分隔线的大小
    • setLeftComponent

      public void setLeftComponent(Component  comp)
      将组件设置到分隔线的左侧(或上方)。
      参数:
      comp - 在该位置显示的 Component
    • getLeftComponent

      @BeanProperty (bound =false, preferred =true, description ="The component to the left (or above) the divider.") public Component  getLeftComponent()
      返回分隔符左侧(或上方)的组件。
      返回:
      Component 显示在该位置
    • setTopComponent

      @BeanProperty (bound =false, description ="The component above, or to the left of the divider.") public void setTopComponent(Component  comp)
      将组件设置在分隔线上方或左侧。
      参数:
      comp - 在该位置显示的 Component
    • getTopComponent

      public Component  getTopComponent()
      返回上方或分隔符左侧的组件。
      返回:
      Component 显示在该位置
    • setRightComponent

      @BeanProperty (bound =false, preferred =true, description ="The component to the right (or below) the divider.") public void setRightComponent(Component  comp)
      将组件设置到分隔线的右侧(或下方)。
      参数:
      comp - 在该位置显示的 Component
    • getRightComponent

      public Component  getRightComponent()
      返回分隔符右侧(或下方)的组件。
      返回:
      Component 显示在该位置
    • setBottomComponent

      @BeanProperty (bound =false, description ="The component below, or to the right of the divider.") public void setBottomComponent(Component  comp)
      将组件设置在分隔线下方或右侧。
      参数:
      comp - 在该位置显示的 Component
    • getBottomComponent

      public Component  getBottomComponent()
      返回下方或分隔符右侧的组件。
      返回:
      Component 显示在该位置
    • setOneTouchExpandable

      @BeanProperty (description ="UI widget on the divider to quickly expand/collapse the divider.") public void setOneTouchExpandable(boolean newValue)
      设置 oneTouchExpandable 属性的值,对于 JSplitPane 必须是 true 才能在分隔线上提供 UI 小部件以快速展开/折叠分隔线。此属性的默认值为 false 。有些外观可能不支持一键式扩展;他们将忽略此属性。
      参数:
      newValue - true 指定拆分窗格应提供折叠/展开小部件
      参见:
    • isOneTouchExpandable

      public boolean isOneTouchExpandable()
      获取 oneTouchExpandable 属性。
      返回:
      oneTouchExpandable 属性的值
      参见:
    • setLastDividerLocation

      @BeanProperty (description ="The last location the divider was at.") public void setLastDividerLocation(int newLastLocation)
      将分隔线所在的最后位置设置为 newLastLocation
      参数:
      newLastLocation - 一个整数,以像素为单位指定最后一个分隔符位置,从窗格的左(或上)边缘到分隔符的左(或上)边缘
    • getLastDividerLocation

      public int getLastDividerLocation()
      返回分隔线所在的最后位置。
      返回:
      一个整数,指定最后一个分隔符位置作为从窗格的左(或上)边缘到分隔符的左(或上)边缘的像素计数
    • setOrientation

      @BeanProperty (enumerationValues ={"JSplitPane.HORIZONTAL_SPLIT","JSplitPane.VERTICAL_SPLIT"}, description ="The orientation, or how the splitter is divided.") public void setOrientation(int orientation)
      设置方向,或拆分器的划分方式。选项是:
      • JSplitPane.VERTICAL_SPLIT(组件的上方/下方)
      • JSplitPane.HORIZONTAL_SPLIT(组件的左/右方向)
      参数:
      orientation - 指定方向的整数
      抛出:
      IllegalArgumentException - 如果方向不是以下之一:HORIZONTAL_SPLIT 或 VERTICAL_SPLIT。
    • getOrientation

      public int getOrientation()
      返回方向。
      返回:
      给出方向的整数
      参见:
    • setContinuousLayout

      @BeanProperty (description ="Whether the child components are continuously redisplayed and laid out during user intervention.") public void setContinuousLayout(boolean newContinuousLayout)
      设置 continuousLayout 属性的值,该属性必须为 true,以便在用户干预期间不断重新显示和布局子组件。此属性的默认值取决于外观。有些外观可能不支持连续布局;他们将忽略此属性。
      参数:
      newContinuousLayout - true 组件是否应随着分隔线改变位置而不断重绘
      参见:
    • isContinuousLayout

      public boolean isContinuousLayout()
      获取 continuousLayout 属性。
      返回:
      continuousLayout 属性的值
      参见:
    • setResizeWeight

      @BeanProperty (description ="Specifies how to distribute extra space when the split pane resizes.") public void setResizeWeight(double value)
      指定当拆分窗格的大小发生变化时如何分配额外空间。默认值 0 表示右/底部组件获得所有额外空间(左/顶部组件固定),而值 1 指定左/顶部组件获得所有额外空间(右/底部组件固定)。具体来说,左/顶部组件获得 (weight * diff) 额外空间,右/底部组件获得 (1 - weight) * diff 额外空间。
      参数:
      value - 如上所述
      抛出:
      IllegalArgumentException - 如果 value 是 < 0 或 > 1
      自从:
      1.3
    • getResizeWeight

      public double getResizeWeight()
      返回确定额外空间分配方式的数字。
      返回:
      如何在拆分窗格的大小调整时分配额外空间
      自从:
      1.3
    • resetToPreferredSizes

      public void resetToPreferredSizes()
      根据子组件的首选大小布置 JSplitPane 布局。这可能会导致更改分隔线位置。
    • setDividerLocation

      @BeanProperty (description ="The location of the divider.") public void setDividerLocation(double proportionalLocation)
      将分隔符位置设置为 JSplitPane 大小的百分比。

      此方法是根据 setDividerLocation(int) 实现的。此方法会根据当前大小立即更改拆分窗格的大小。如果拆分窗格未正确实现并显示在屏幕上,则此方法将无效(新的分隔符位置将变为(当前大小 * proportionalLocation),即 0)。

      参数:
      proportionalLocation - 指定百分比的双精度浮点值,从零(上/左)到 1.0(下/右)
      抛出:
      IllegalArgumentException - 如果指定位置 < 0 或 > 1.0
    • setDividerLocation

      @BeanProperty (description ="The location of the divider.") public void setDividerLocation(int location)
      设置分隔线的位置。这将传递给外观实现,然后通知监听器。小于 0 的值意味着应将分隔符重置为尝试遵守左/顶部组件的首选大小的值。通知听众后,最后的分隔符位置通过 setLastDividerLocation 更新。
      参数:
      location - 指定 UI 特定值(通常是像素数)的 int
    • getDividerLocation

      public int getDividerLocation()
      返回传递给 setDividerLocation 的最后一个值。此方法返回的值可能与实际分隔符位置不同(如果setDividerLocation 传递的值大于当前大小)。
      返回:
      指定分隔符位置的整数
    • getMinimumDividerLocation

      @BeanProperty (bound =false, description ="The minimum location of the divider from the L&F.") public int getMinimumDividerLocation()
      从外观实现中返回分隔线的最小位置。
      返回:
      一个整数,指定最小位置的特定于 UI 的值(通常是像素数);或者 -1 如果 UI 是 null
    • getMaximumDividerLocation

      @BeanProperty (bound =false) public int getMaximumDividerLocation()
      从外观实现中返回分隔线的最大位置。
      返回:
      一个整数,指定最大位置的特定于 UI 的值(通常是像素数);或者 -1 如果 UI 是 null
    • remove

      public void remove(Component  component)
      从窗格中删除子组件 component。根据需要重置 leftComponentrightComponent 实例变量。
      重写:
      remove 在类 Container
      参数:
      component - 要删除的 Component
      参见:
    • remove

      public void remove(int index)
      删除指定索引处的 Component。根据需要更新 leftComponentrightComponent 实例变量,然后是超级消息。
      重写:
      remove 在类 Container
      参数:
      index - 指定要删除的组件的整数,其中 1 指定左/顶部组件,2 指定底部/右组件
      参见:
    • removeAll

      public void removeAll()
      从拆分窗格中删除所有子组件。重置 leftComonentrightComponent 实例变量。
      重写:
      removeAll 在类 Container
      参见:
    • isValidateRoot

      @BeanProperty (hidden =true) public boolean isValidateRoot()
      返回 true,因此在此 JSplitPane 的任何后代上调用 revalidate 将导致请求排队,该请求将验证 JSplitPane 及其所有后代。
      重写:
      isValidateRoot 在类 JComponent
      返回:
      true
      参见:
    • addImpl

      protected void addImpl(Component  comp, Object  constraints, int index)
      将指定的组件添加到此拆分窗格。如果 constraints 标识左/上或右/下子组件,并且之前添加了具有该标识符的组件,它将被删除,然后 comp 将被添加到它的位置。如果 constraints 不是已知标识符之一,布局管理器可能会抛出 IllegalArgumentException

      可能的约束对象(字符串)是:

      • JSplitPane.TOP
      • JSplitPane.LEFT
      • JSplitPane.BOTTOM
      • JSplitPane.RIGHT
      如果 constraints 对象是 null ,则将组件添加到第一个可用位置(如果打开则为左/上,否则为右/下)。
      重写:
      addImpl 在类 Container
      参数:
      comp - 要添加的组件
      constraints - 一个 Object 指定此组件的布局约束(位置)
      index - 一个整数,指定容器列表中的索引。
      抛出:
      IllegalArgumentException - 如果 constraints 对象与现有组件不匹配
      参见:
    • paintChildren

      protected void paintChildren(Graphics  g)
      在向 super 发送消息后,子类化为使用 finishedPaintingChildren 向 UI 发送消息,以及绘制边框。
      重写:
      paintChildren 在类 JComponent
      参数:
      g - 在其中绘制的 Graphics 上下文
      参见:
    • paramString

      protected String  paramString()
      返回此 JSplitPane 的字符串表示形式。此方法仅用于调试目的,返回字符串的内容和格式可能因实现而异。返回的字符串可能为空,但可能不是 null
      重写:
      paramString 在类 JComponent
      返回:
      这个 JSplitPane 的字符串表示。
    • getAccessibleContext

      @BeanProperty (bound =false, expert =true, description ="The AccessibleContext associated with this SplitPane.") public AccessibleContext  getAccessibleContext()
      获取与此 JSplitPane 关联的 AccessibleContext。对于拆分窗格,AccessibleContext 采用 AccessibleJSplitPane 的形式。如有必要,将创建一个新的 AccessibleJSplitPane 实例。
      指定者:
      getAccessibleContext 在接口 Accessible
      重写:
      getAccessibleContext 在类 Component
      返回:
      作为此 JSplitPane 的 AccessibleContext 的 AccessibleJSplitPane