JavaFX:未装饰的窗口 [英] JavaFX: Undecorated Window

查看:23
本文介绍了JavaFX:未装饰的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试发出 Windows PC Toast 通知.现在我混合使用 Swing 和 JavaFX,因为我没有找到用 FX 制作未装饰窗口的方法.我更愿意只使用 JavaFX.

I am attempting to make a Windows PC Toast notification. Right now I am using a mixture of Swing and JavaFX because I did not find a way to make an undecorated window with FX. I would much prefer to only use JavaFX.

那么,我怎样才能制作一个未装饰的窗户?

So, how can I make an undecorated window?

我发现您可以直接使用 new Stage(StageStyle.UNDECORATED) 创建舞台.

I have discovered that you can create a stage directly with new Stage(StageStyle.UNDECORATED).

现在我需要知道的是如何初始化工具包,以便我可以在 MyApplication 中调用我的 start(Stage stage) 方法.(扩展应用程序)

Now all I need to know is how to initialize the toolkit so I can call my start(Stage stage) method in MyApplication. (which extends Application)

我通常调用 Application.launch(MyApplication.class, null),但这使我免于创建 Stage 和初始化 Toolkit.

I usually call Application.launch(MyApplication.class, null), however that shields me from the creation of the Stage and initialization of the Toolkit.

那么我该如何做这些事情才能让我直接使用start(new Stage(StageStyle.UNDECORATED))?

So how can I do these things to allow me to use start(new Stage(StageStyle.UNDECORATED)) directly?

推荐答案

我不明白你初步调用 start() 方法将舞台设置为未装饰的动机,但下面的代码应该做你想做的实现.

I don't get your motivation for preliminary calling the start()-method setting a stage as undecorated, but the following piece of code should do what you want to achieve.

package decorationtest;

import javafx.application.Application;
import javafx.stage.StageStyle;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class DecorationTest extends Application {

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

    @Override
    public void start(Stage primaryStage) {
        primaryStage.initStyle(StageStyle.UNDECORATED);

        Group root = new Group();
        Scene scene = new Scene(root, 100, 100);

        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

这篇关于JavaFX:未装饰的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆