You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JavaFX应用自定义全屏退出规则失效,无法退出全屏的问题求助

JavaFX应用自定义全屏退出规则失效,无法退出全屏的问题求助

最近在学JavaFX,想做个小功能——只有输入"abcd"才能退出全屏模式,结果试了各种办法都不管用,现在完全退不出全屏了,求大佬帮忙看看哪里错了😭

我设置了全屏退出提示,也指定了退出的键组合,但就是没效果。用的是JavaFX 17和Java 18版本。

以下是我写的代码:

package org.example.first;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCombination;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

import java.io.IOException;

public class HelloApplication extends Application {
    @Override
    public void start(Stage stage) throws IOException {
        Group root = new Group();
        Scene scene = new Scene(root, Color.BLACK);

        Image icon = new Image("file.png");

        stage.setTitle("MyApplication");
        stage.setScene(scene);
        stage.getIcons().add(icon);

        stage.setFullScreen(true);
        stage.setFullScreenExitHint("To exit fullscreen, write abcd");
        stage.setFullScreenExitKeyCombination(KeyCombination.valueOf("abcd"));
        stage.show();
    }

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

备注:内容来源于stack exchange,提问作者armenia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 10:48:11