gpt4 book ai didi

JavaFX:如果内部有项目,SplitPane 会在调整大小时更改分隔线位置

转载 作者:搜寻专家 更新时间:2023-11-01 02:21:12 25 4
gpt4 key购买 nike

我有以下代码:

public class JavaFxApplication2 extends Application {

@Override
public void start(Stage stage) throws Exception {
SplitPane splitPane=new SplitPane();
VBox vBox1=new VBox();
vBox1.setStyle("-fx-background-color: red");
VBox vBox2=new VBox();
vBox2.setStyle("-fx-background-color: blue");
splitPane.getItems().add(vBox1);
splitPane.getItems().add(vBox2);
splitPane.getDividers().get(0).setPosition(0);
Scene scene=new Scene(splitPane, 200, 400);
stage.setScene(scene);
stage.show();
}
}

这是我运行应用程序时的输出:
enter image description here
现在我调整大小并使舞台变大:
enter image description here
如您所见,分隔线位置现在不为 0。如何在调整大小时禁用分隔线位置更改?

最佳答案

默认情况下,SplitPane 包含的所有节点都会调整大小,因此是“游走的分隔线”。

您可以使用 setResizableWithParent避免调整左侧 VBox 的大小:

SplitPane.setResizableWithParent(vBox1, false);

Sets a node in the SplitPane to be resizable or not when the SplitPane is resized. By default all node are resizable. Setting value to false will prevent the node from being resized.

如果您不想调整正确的 VBox 大小,则还必须为该节点调用此方法。

关于JavaFX:如果内部有项目,SplitPane 会在调整大小时更改分隔线位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41813087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com