【问题标题】:Is the extra top space in a stage included in the size of the scene?舞台上额外的顶部空间是否包含在场景的大小中?
【发布时间】:2015-05-29 02:52:11
【问题描述】:

如果我想要一个场景是 500 x 500... 那是让舞台变成 550 x 550 还是让场景变成 450 x 450 和舞台 500 x 500?场景上方包含关闭、恢复和最小化按钮的额外标题栏空间的宽度和长度是多少?

【问题讨论】:

    标签: java javafx scene stage


    【解决方案1】:

    不,舞台顶部的额外空间不包括在场景的大小中。

    如果您想知道确切的大小,则取决于平台。一个非常简单的验证示例是创建500 x 500 的场景并将舞台设置为X=0, Y=0 并检查mouse co-ordinates 以测量大小。

    public class MyStageSize extends Application {
    
        @Override
        public void start(Stage stage) {
            Label label = new Label();
            VBox root = new VBox(label);
            root.setAlignment(Pos.CENTER);
            Scene scene = new Scene(root, 500, 500);
            stage.setScene(scene);
            stage.setX(0);
            stage.setY(0);
            stage.show();
            scene.setOnMouseMoved(e -> label.setText(String.valueOf("X = " + e.getScreenX() + "\nY = " + e.getScreenY())));
        }
        public static void main(String[] args) {
            launch(args);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-07-21
      • 2020-07-02
      • 2018-07-05
      • 2019-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多