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.
我是否遗漏了全屏模式与最大化和未修饰模式有何不同?我是否使用全屏模式不当?
我在 CentOS 6.5 上使用 Java 版本 1.8.0_20 和 Gnome。
这是我的 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!");
}
}
在使用java版本“1.8.0_40”重复这个问题后,我终于找到了如何解决这个问题!
popupStage.initStyle(StageStyle.UTILITY);
Stage.initStyle(StageStyle) -- JavaFX 8 http://docs.oracle.com/javase/8/javafx/api/javafx/stage/Stage.html#initStyle-javafx.stage.StageStyle-
给弹出窗口一种风格StageStyle.UTILITY
即使在弹出窗口之外单击,似乎也会将弹出窗口保留在全屏窗口前面。
我在使用新版本时看到了同样的问题Alert
java 1.8.0_40 中的类,并将样式设置为StageStyle.UTILITY
也修复了这个问题(Dialog.initStyle(StageStyle) -- JavaFX 8 http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Dialog.html#initStyle-javafx.stage.StageStyle-).
我不知道为什么这有效。
边注:
看起来像是删除了对popupStage.initOwner(...)
允许弹出窗口出现在全屏应用程序上方,但在弹出窗口之外单击会导致弹出窗口消失。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)