How to make javafx.scene.Scene resize while maintaining an aspect ratio?

后端 未结 2 1079
说谎
说谎 2021-01-06 03:06

I\'m writing an application with JavaFX 2.2.7-b01.

Here is an example of the code I currently have. How can I allow the application window to be resized but maintain

相关标签:
2条回答
  • 2021-01-06 03:38

    In netbeans using Java Fx Scene Builder provide you can use AnchorPane Constraints to set Resizing of stage.

    0 讨论(0)
  • 2021-01-06 03:45

    > How to make javafx.scene.Scene resize while maintaining an aspect ratio?

    By manipulating the stage size instead of scene:

    @Override
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Play by resizing the window");
        VBox root = new VBox();
        root.getChildren().add(btn);
        root.setStyle("-fx-background-color: gray");
    
        Scene scene = new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.minWidthProperty().bind(scene.heightProperty().multiply(2));
        primaryStage.minHeightProperty().bind(scene.widthProperty().divide(2));
        primaryStage.show();
    }
    
    0 讨论(0)
提交回复
热议问题