我正在尝试在JavaFX中弹出一个对话框,覆盖在全屏的主舞台上。当我创建弹出窗口时,它意外地隐藏在我的全屏主舞台后面,直到该舞台通过ESC退出全屏模式。如果我将我的主舞台最大化并去掉边框而不是全屏幕,则我的弹出窗口将如预期一样显示在主舞台上方。
我是否漏掉了全屏模式与最大化和去掉边框模式之间的区别?我是否错误地使用了全屏模式?
我在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!");
}
}
Platform.runLater(()->popupStage.requestFocus());
看看是否有帮助。 - brian