如何调整JavaFX 3D SubScene的大小?

fho*_*fho 5 java javafx

此代码将创建一个300x300大的3d场景.调整包含窗口/舞台大小时,视口不会调整大小.

Parent没有任何widthheight属性.如何调整Parent和/或SubScene更改窗口大小的大小?

Mit*_*ead 9

将它绑定到父级

SubScene subscene = new SubScene(root, 1024, 768, true, null);
subscene.setFill(Color.GREY);
subscene.setCamera(camera);
StackPane stackPane = new StackPane();
stackPane.getChildren().add(subscene);
subscene.heightProperty().bind(stackPane.heightProperty());
subscene.widthProperty().bind(stackPane.widthProperty());
Run Code Online (Sandbox Code Playgroud)


小智 6

我发现将 SubScene 对象的托管属性设置为 false 也很重要。

subscene.setManaged(false);
Run Code Online (Sandbox Code Playgroud)

这样,SubScene 对象的大小不会影响其父 StackPane 对象的大小,并且在减小 StackPane 对象的大小时调整大小也将起作用。