Java JSplitPane

2025年3月17日 | 阅读 3 分钟

JSplitPane用于分割两个组件。这两个组件根据外观和感觉实现进行分割,并且可以由用户调整大小。如果两个组件的最小大小大于分割窗格的大小,则分隔符将不允许您调整其大小。

分割窗格中的两个组件可以使用 JSplitPane.HORIZONTAL_SPLIT 从左到右对齐,或者使用 JSplitPane.VERTICAL_SPLIT 从上到下对齐。当用户调整组件大小时,组件的最小大小用于确定组件可以设置的最大/最小位置。

嵌套类

修饰符和类型Class描述
受保护的类JSplitPane.AccessibleJSplitPane此类实现了对 JsplitPane 类的可访问性支持。

有用的字段

修饰符和类型字段描述
static String底部它用于将一个组件添加到另一个组件下方。
static StringCONTINUOUS_LAYOUT_PROPERTY连续布局的绑定属性名称。
static String分隔符它用于添加一个将代表分隔符的组件。
static intHORIZONTAL_SPLIT水平分割表示组件沿 x 轴分割。
protected intlastDividerLocation分割窗格的先前位置。
protected ComponentleftComponent左侧或顶部组件。
static intVERTICAL_SPLIT垂直分割表示组件沿 y 轴分割。
protected ComponentrightComponent右侧或底部组件。
protected intorientation视图的分割方式。

构造函数

构造函数描述
JSplitPane()它创建一个新的 JsplitPane,配置为水平并排排列子组件,使用两个按钮作为组件。
JSplitPane(int newOrientation)它创建一个新的 JsplitPane,配置为指定的方向。
JSplitPane(int newOrientation, boolean newContinuousLayout)它创建一个新的 JsplitPane,具有指定的方向和重绘样式。
JSplitPane(int newOrientation, boolean newContinuousLayout, Component newLeftComponent, Component newRightComponent)它创建一个新的 JsplitPane,具有指定的方向和重绘样式,以及指定的组件。
JSplitPane(int newOrientation, Component newLeftComponent, Component newRightComponent)它创建一个新的 JsplitPane,具有指定的方向和指定的组件。

有用的方法

修饰符和类型方法描述
受保护的 voidaddImpl(Component comp, Object constraints, int index)它将指定的组件添加到此分割窗格中。
AccessibleContextgetAccessibleContext()它获取与此 JSplitPane 关联的 AccessibleContext。
intgetDividerLocation()它返回传递给 setDividerLocation 的最后一个值。
intgetDividerSize()它返回分隔符的大小。
组件getBottomComponent()它返回分隔符下方或右侧的组件。
组件getRightComponent()它返回分隔符右侧(或下方)的组件。
SplitPaneUIgetUI()它返回提供当前外观和感觉的 SplitPaneUI。
booleanisContinuousLayout()它获取 continuousLayout 属性。
booleanisOneTouchExpandable()它获取 oneTouchExpandable 属性。
voidsetOrientation(int orientation)它获取方向,或分隔符的分割方式。

JSplitPane示例

输出

Java JSplitpane
下一个主题Java JTextPane