Javafx:如何访问窗口标题宽宽参数?

发布于 2025-01-23 22:19:59 字数 1303 浏览 2 评论 0原文

让我们使用场景图组的Javafx程序 - >帆布。根(组)放在场景中,场景连接到窗口,特别是阶段。

一旦窗口显示在屏幕上,用户就可以调整窗口大小。高度和宽度可能会更改。但是,通常对如何制作窗口有一些限制。值得注意的是,该窗口具有标题栏,并且具有关联的最小宽度。另请参见下图。

我怀疑TitleBar的最小宽度取决于平台,进一步取决于平台的用户设置。因此,需要一种访问参数的更多一般方法。

  • 是否可以通常访问窗口标题栏的最小(稳定)宽度?如果是这样,怎么样?

一张可以简单地解释我要寻找的长度的图片:


这是用于测试的MWE(请尽可能减少Horisontal宽度):

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.stage.Stage;


public class HelloApplication extends Application {
    @Override
    public void start(Stage stage) {
        Group group = new Group();
        Canvas canvas = new Canvas(200, 200);
        group.getChildren().add(canvas);
        
        Scene scene = new Scene(group);
        stage.setTitle("Title");
        stage.setScene(scene);
        stage.show();

        //System.out.println(stage.getMinWidth()); // default is also 0.0
        //stage.setMinWidth(0); // we can see that a lower value than the sought-for minimum value will not have an effect


    }

    public static void main(String[] args) {
        launch();
    }
}

Let us have a JavaFX program with the scene graph Group -> Canvas. The root (Group) is put inside a Scene, and the Scene is attached to a Window, specifically a Stage.

Once the Window is displayed on screen, the user may resize the Window. The height and the width may be changed. However, there are usually some restrictions to how small the Window can be made. Notably the Window has a titlebar, and it has an associated minimum width. See also the picture below.

I suspect that the minimum width of the titlebar is platform-dependent and further depends on user settings of the platform. So a more-less general way of accessing the parameter is desirable.

  • Is it possible to generally access the minimum (stable) width of the titlebar of a Window? If so, how?

A picture to explain concisely which length I am looking for:

Example

(In the picture, the Window could not be made any smaller in the horisontal dimension).


Here is a MWE for testing (please try to decrease the horisontal width as far as possible):

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.stage.Stage;


public class HelloApplication extends Application {
    @Override
    public void start(Stage stage) {
        Group group = new Group();
        Canvas canvas = new Canvas(200, 200);
        group.getChildren().add(canvas);
        
        Scene scene = new Scene(group);
        stage.setTitle("Title");
        stage.setScene(scene);
        stage.show();

        //System.out.println(stage.getMinWidth()); // default is also 0.0
        //stage.setMinWidth(0); // we can see that a lower value than the sought-for minimum value will not have an effect


    }

    public static void main(String[] args) {
        launch();
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文