【问题标题】:How to resize a JavaFX 3D SubScene?如何调整 JavaFX 3D 子场景的大小?
【发布时间】:2014-07-07 08:43:06
【问题描述】:

This code 将创建一个 300x300 大的 3d 场景。当我调整包含窗口/舞台的大小时,视口不会调整大小。

Parent 没有任何 widthheight 属性。如何调整Parent 和/或SubScene 的大小以适应不断变化的窗口大小?

【问题讨论】:

    标签: java javafx


    【解决方案1】:

    将其绑定到父级

    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());
    

    【讨论】:

    • 我前段时间知道了,不过还是谢谢。
    • 父类不包含 heightProperty() 或 widthProperty()。
    • 你用的是什么父类?你可以在父类中添加一个stackpane然后绑定子场景吗?
    【解决方案2】:

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

    subscene.setManaged(false);
    

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

    【讨论】:

    • 正是我需要缩小子场景
    【解决方案3】:

    通过以下方法,您可以将您的 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
                    }
                }
                }
    

    【讨论】:

      【解决方案4】:

      Ypu 可能想使用 getTransforms().add(new Scale(parameter1, para2,...));

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多