I'm working on an application that has a secondary Stage that has alwaysInFront set to true. When a modal dialog is opened from the primary Stage, it appears behind the secondary stage but blocks input (since the modality for the dialog defaults to application-wide)...so the user sometimes ends up blocked, which is a bit awkward. It makes it appear as though the application has frozen. Here is a minimal sample application to reproduce this:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class DialogTest3 extends Application {
private Label label;
@Override
public void start(Stage primaryStage) throws Exception {
HBox content = new HBox(10);
Button b1 = new Button("Click first to open ALWAYS IN FRONT window");
b1.setOnAction((event) -> {
// create a new stage
Stage stage = new Stage();
StackPane pane = new StackPane();
this.label = new Label("This window is ALWAYS IN FRONT.");
pane.getChildren().add(this.label);
pane.setPrefWidth(500);
pane.setPrefHeight(300);
stage.setScene(new Scene(pane));
stage.setAlwaysOnTop(true);
stage.show();
});
content.getChildren().add(b1);
Button b2 = new Button("Click for dialog");
b2.setOnAction((event) -> {
this.label.setText("The dialog has been created even if you can't see it.");
Dialog<ButtonType> dialog = new Dialog<>();
dialog.initOwner(primaryStage);
dialog.setContentText("This is a test.");
dialog.getDialogPane().getButtonTypes().add(ButtonType.OK);
dialog.showAndWait();
});
content.getChildren().add(b2);
Scene scene = new Scene(content, 600, 500);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I'm not exactly sure how this *should* behave, so maybe it is not a bug. I did see some info on how AWT handles this:
"However, there is a way around this: If d is set to be always on top as well (d.setAlwaysOnTop(true)), then the dialog box will be on top of the frame at all times."
http://www.oracle.com/technetwork/java/modality-137604.html
I think it would make sense for JavaFX to provide an equivalent mechanism to resolve this conflict.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class DialogTest3 extends Application {
private Label label;
@Override
public void start(Stage primaryStage) throws Exception {
HBox content = new HBox(10);
Button b1 = new Button("Click first to open ALWAYS IN FRONT window");
b1.setOnAction((event) -> {
// create a new stage
Stage stage = new Stage();
StackPane pane = new StackPane();
this.label = new Label("This window is ALWAYS IN FRONT.");
pane.getChildren().add(this.label);
pane.setPrefWidth(500);
pane.setPrefHeight(300);
stage.setScene(new Scene(pane));
stage.setAlwaysOnTop(true);
stage.show();
});
content.getChildren().add(b1);
Button b2 = new Button("Click for dialog");
b2.setOnAction((event) -> {
this.label.setText("The dialog has been created even if you can't see it.");
Dialog<ButtonType> dialog = new Dialog<>();
dialog.initOwner(primaryStage);
dialog.setContentText("This is a test.");
dialog.getDialogPane().getButtonTypes().add(ButtonType.OK);
dialog.showAndWait();
});
content.getChildren().add(b2);
Scene scene = new Scene(content, 600, 500);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I'm not exactly sure how this *should* behave, so maybe it is not a bug. I did see some info on how AWT handles this:
"However, there is a way around this: If d is set to be always on top as well (d.setAlwaysOnTop(true)), then the dialog box will be on top of the frame at all times."
http://www.oracle.com/technetwork/java/modality-137604.html
I think it would make sense for JavaFX to provide an equivalent mechanism to resolve this conflict.