舞台处于全屏模式时隐藏 JavaFX 弹出窗口 [英] JavaFX popup hidden when stage is in fullscreen mode

查看:67
本文介绍了舞台处于全屏模式时隐藏 JavaFX 弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 javafx 中的全屏初级阶段弹出一个对话框.当我创建我的弹出窗口时,它意外地隐藏在我的全屏主舞台后面,直到舞台从全屏模式中移除(通过 ESC).如果我将我的主舞台最大化且未装饰而不是全屏,那么我的弹出窗口将按预期显示在主舞台的顶部.

我是否遗漏了关于全屏模式与最大化和未修饰模式有何不同?我是否不正确地使用全屏模式?

我在带有 Gnome 的 CentOS 6.5 上使用 java 版本 1.8.0_20.

这是我的 SSCCE:

import javafx.application.*;导入javafx.scene.*;导入javafx.scene.control.*;导入javafx.stage.*;公共类TestApplication扩展应用程序{私人舞台primaryStage;公共静态无效主要(字符串[]参数){启动(参数);}公共无效开始(阶段阶段){this.primaryStage = 阶段;//创建全屏主舞台.primaryStage.setTitle("主舞台");primaryStage.setScene(new Scene(createRoot()));primaryStage.setFullScreen(true);主舞台.show();}私人父母 createRoot() {Button button = new Button("显示弹窗");button.setOnAction((事件) -> showPopup());返回按钮;}私人无效showPopup(){//创建一个弹出窗口,该弹出窗口应位于主阶段之上.舞台 popupStage = new Stage();popupStage.setScene(新场景(createPopupRoot()));popupStage.setTitle("弹出舞台");popupStage.initModality(Modality.WINDOW_MODAL);popupStage.initOwner(primaryStage);popupStage.show();}私人父母 createPopupRoot() {return new Label("这是一个弹出窗口!");}}

解决方案

在java版本'1.8.0_40'重复这个问题后,我终于找到了解决这个问题的方法!

popupStage.initStyle(StageStyle.UTILITY);

阶段.initStyle(StageStyle) -- JavaFX 8

为弹出窗口赋予 StageStyle.UTILITY 样式似乎使弹出窗口保持在全屏窗口的前面,即使在弹出窗口外部单击也是如此.

我在 java 1.8.0_40 中使用新的 Alert 类时看到了同样的问题,并且将样式设置为 StageStyle.UTILITY 也解决了这个问题(Dialog.initStyle(StageStyle) -- JavaFX 8).

我不知道为什么会这样.

旁注:

看起来移除对 popupStage.initOwner(...) 的调用允许弹出窗口出现在全屏应用程序上方,但在弹出窗口外部单击会导致弹出窗口消失.p>

I am trying to popup a dialog over my fullscreen primary stage in javafx. When I create my popup, it is unexpectedly hidden behind my fullscreen primary stage until the stage is removed from fullscreen mode (via ESC). If I make my primary stage maximized and undecorated instead of fullscreen, then my popup will appear on top of the primary stage as expected.

Am I missing something about how fullscreen mode is different than maximized and undecorated mode? Am I using fullscreen mode improperly?

I am using java version 1.8.0_20 on CentOS 6.5 with Gnome.

Here is my SSCCE:

import javafx.application.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.stage.*;

public class TestApplication extends Application {
    private Stage primaryStage;

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

    public void start(Stage stage) {
        this.primaryStage = stage;

        // Create a fullscreen primary stage.    
        primaryStage.setTitle("Main Stage");
        primaryStage.setScene(new Scene(createRoot()));
        primaryStage.setFullScreen(true);

        primaryStage.show();
    }       

    private Parent createRoot() {
        Button button = new Button("Show popup");
        button.setOnAction((event) -> showPopup());

        return button;
    }

    private void showPopup() {
        // Create a popup that should be on top of the primary stage.
        Stage popupStage = new Stage();

        popupStage.setScene(new Scene(createPopupRoot()));
        popupStage.setTitle("Popup Stage");
        popupStage.initModality(Modality.WINDOW_MODAL);
        popupStage.initOwner(primaryStage);

        popupStage.show();
    }

    private Parent createPopupRoot() {
        return new Label("This is a popup!");
    }
}

解决方案

After repeating this problem with java version '1.8.0_40', I finally found how to fix this problem!

popupStage.initStyle(StageStyle.UTILITY);

Stage.initStyle(StageStyle) -- JavaFX 8

Giving the popup a style of StageStyle.UTILITY seems to keep the popup in front of the fullscreen window even when clicking outside of the popup.

I saw this same issue when using the new Alert class in java 1.8.0_40, and setting the style to StageStyle.UTILITY fixed that as well (Dialog.initStyle(StageStyle) -- JavaFX 8).

I don't know why this works.

Side Note:

It looks like removing the call to popupStage.initOwner(...) allows the popup to appear above the full screen application, but clicking outside of the popup causes the popup to disappear.

这篇关于舞台处于全屏模式时隐藏 JavaFX 弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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