【发布时间】:2014-07-07 08:43:06
【问题描述】:
This code 将创建一个 300x300 大的 3d 场景。当我调整包含窗口/舞台的大小时,视口不会调整大小。
Parent 没有任何 width 或 height 属性。如何调整Parent 和/或SubScene 的大小以适应不断变化的窗口大小?
【问题讨论】:
This code 将创建一个 300x300 大的 3d 场景。当我调整包含窗口/舞台的大小时,视口不会调整大小。
Parent 没有任何 width 或 height 属性。如何调整Parent 和/或SubScene 的大小以适应不断变化的窗口大小?
【问题讨论】:
将其绑定到父级
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());
【讨论】:
我发现将 SubScene 对象的托管属性设置为 false 也很重要。
subscene.setManaged(false);
这样,SubScene 对象的大小不会影响其父 StackPane 对象的大小,并且在减小 StackPane 对象的大小时也可以调整大小。
【讨论】:
通过以下方法,您可以将您的 SubScene 放入任何扩展 Pane 类的类中(例如 BorderPane、GridPane 等)。 subScene 的大小也可以与您的 Pane 不同:
public class GuiControler extends BorderPane implements Initializable,ChangeListener {
//Set a changeListener to the Stage's Window and Implement the ChangeListener in the class where you want to make the subScene scaling.
stage.widthProperty().addListener(this);
stage.heightProperty().addListener(this);
//....
@Override
public void changed(ObservableValue observable, Object oldValue, Object newValue) {
double width = stage.getWidth();
double height = stage.getHeight();
if(observable.equals(this.widthProperty())) {
double scale = width / 400; // 400 is my initial width size of the stage (main java app window) window
subScene.setWidth(200*scale); // 200 is my initial size of the subscene window
}else if(observable.equals(this.heightProperty())){
double scale = height / 400; // 400 is initial size for stage height window
subScene.setHeight(250*scale); // 250 is initial size for subScene width
}
}
}
【讨论】:
Ypu 可能想使用 getTransforms().add(new Scale(parameter1, para2,...));
【讨论】: