防止SplitPane的一面在javafx中调整大小

Joh*_*ohn 1 java javafx splitpane

我有一个布局,我有一个垂直拆分窗格,分为两个组件.我希望生长的分割板右侧内部的组件(它是一个图像),但拆分窗格左侧的组件我希望保持在完全相同的位置,当窗口处的分隔符完全相同的位置被放大了.

我试图将左侧的AnchorPane包装在一个Vbox中,它似乎工作,除非调整窗口大小时左侧的所有组件都向下移动.当我将它包装在HBox中时也会发生这种情况.

我想不出解决这个问题的最佳方法.我正在使用场景构建器,我仍然是Javafx的新手.有人可以帮忙吗?

谢谢!

Nic*_*tto 5

调用setMinWidth并且setMaxWidth必须不会以相同的固定值增长的组件将阻止用户更改分隔符位置.

例如,假设您想要100左侧组件的最大大小,代码可以是:

SplitPane pane = new SplitPane();

double leftComponentSize = 100.0;
VBox leftComponent = new VBox();
// Set the min and max width to a fixed size
leftComponent.setMinWidth(leftComponentSize);
leftComponent.setMaxWidth(leftComponentSize);
...
pane.getItems().addAll(leftComponent, rightComponent);
// Initialize the divider positions to allocate the expected size 
// to the left component according to the size of the window
pane.setDividerPositions(leftComponentSize / stage.getScene().getWidth());
Run Code Online (Sandbox Code Playgroud)