Reputation: 252
I have a problem with fullscreen stages. I have 1 main stage which enters full screen immediately when application starts, then when the user invokes specific event, I create second stage which is also full screen, but it shows image and its background is transparent, so the main stage and its content is still visible.
The problem is when I display this new stage and set it to fullscreen mode, it makes my main stage exit its fullscreen mode and resize.
Creation of main stage:
root = new StackPane();
scene = new Scene(root);
stage = primaryStage;
scene.setOnKeyReleased(event -> {
if (event.getCode() == KeyCode.ESCAPE) {
close();
}
});
stage.setScene(scene);
stage.setFullScreen(true);
stage.setFullScreenExitHint(null);
stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
stage.setOnCloseRequest(closeRequest -> onClose(closeRequest));
Creation of the new stage:
root = new StackPane();
scene = new Scene(root);
stage = new Stage(StageStyle.TRANSPARENT);
image = new ImageView(new Image(imagePath, 400, 580, true, true));
root.setAlignment(Pos.CENTER);
root.setStyle("-fx-background-color: rgba(0, 0, 0, 0.5)");
root.getChildren().add(image);
scene.setFill(Color.TRANSPARENT);
scene.setOnMousePressed(event -> stage.close());
stage.initOwner(Window.getInstance().getStage());
stage.setScene(scene);
stage.setFullScreen(true);
stage.setFullScreenExitHint(null);
stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
Upvotes: 2
Views: 1786
Reputation: 252
Well I solved this problem by using stage.setMaximized(true) instead of setting it to fullscreen and it worked. I don't know if this is good solution, but I just wanted to post it here.
Upvotes: 3