防止拆分的一侧在Javafx中调整大小



我有一个布局,其中我有一个垂直拆分窗格,将两个组件分开。我想生长的拆分台面右侧的组件(这是一个图像),但是分开窗格的左侧的组件我想在窗口完全相同的位置保持完全相同的位置被放大。

我试图将左侧锚定在Vbox中,但它似乎可以工作,除非调整窗口大小时,左侧的所有组件都会向下移动。当我将其包装在Hbox中时,这也会发生。

我想不出解决此问题的最佳方法。我正在使用场景构建器,但我仍然是Javafx的新手。谁能帮忙?

谢谢!

在组件上调用 setMinWidthsetMaxWidth必须不得与相同的固定值不得不生长,将阻止用户更改分层位置。

因此,假设您要为左组件的最大 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());

最新更新