Exact Java version:
---
8u40 b6 (Win 64x)
Issue
----
The newly added Dialog API opens on the wrong screen in multi-monitor environments if the stage is moved to another screen.
Steps to reproduce (using test code below, and you need more than one monitor)
-----
1. Run program
2. Press button to open a dialog, it's on the same screen as the stage, all fine.
3. Close the dialog
4. Move the main window to another monitor
5. Press button again. Dialog opens centered on the old monitor, non-relative to the stage. Expected would've been that it was opened on the same monitor as where the stage is, ideally centered to to the stage.
Test code
----
import javafx.application.Application;
import javafx.geometry.Insets;
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.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
public class DialogCenterTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
VBox root = new VBox();
Scene scene = new Scene(root);
primaryStage.setWidth(1200);
primaryStage.setHeight(600);
primaryStage.setScene(scene);
Dialog<Void> dlg = new Dialog<>();
dlg.setTitle("Center Test");
dlg.initOwner(primaryStage);
dlg.initModality(Modality.WINDOW_MODAL);
dlg.setResizable(true);
GridPane center = new GridPane();
center.setVgap(6);
center.setHgap(16);
dlg.setHeaderText("I'm The Dialog");
dlg.getDialogPane().setContent(center);
dlg.getDialogPane().getButtonTypes().add(ButtonType.OK);
dlg.getDialogPane().getButtonTypes().add(ButtonType.CLOSE);
Label instructions = new Label("Click the button to open the dialog. Then close it. Move the main window to another screen. Press button again. Popup is now wrong.");
Button b = new Button("Open Dialog");
b.setOnAction(e -> dlg.show());
root.getChildren().add(instructions);
root.getChildren().add(b);
VBox.setMargin(b, new Insets(16, 0, 0, 0));
dlg.setHeight(600);
dlg.setWidth(500);
primaryStage.show();
}
}
---
8u40 b6 (Win 64x)
Issue
----
The newly added Dialog API opens on the wrong screen in multi-monitor environments if the stage is moved to another screen.
Steps to reproduce (using test code below, and you need more than one monitor)
-----
1. Run program
2. Press button to open a dialog, it's on the same screen as the stage, all fine.
3. Close the dialog
4. Move the main window to another monitor
5. Press button again. Dialog opens centered on the old monitor, non-relative to the stage. Expected would've been that it was opened on the same monitor as where the stage is, ideally centered to to the stage.
Test code
----
import javafx.application.Application;
import javafx.geometry.Insets;
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.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
public class DialogCenterTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
VBox root = new VBox();
Scene scene = new Scene(root);
primaryStage.setWidth(1200);
primaryStage.setHeight(600);
primaryStage.setScene(scene);
Dialog<Void> dlg = new Dialog<>();
dlg.setTitle("Center Test");
dlg.initOwner(primaryStage);
dlg.initModality(Modality.WINDOW_MODAL);
dlg.setResizable(true);
GridPane center = new GridPane();
center.setVgap(6);
center.setHgap(16);
dlg.setHeaderText("I'm The Dialog");
dlg.getDialogPane().setContent(center);
dlg.getDialogPane().getButtonTypes().add(ButtonType.OK);
dlg.getDialogPane().getButtonTypes().add(ButtonType.CLOSE);
Label instructions = new Label("Click the button to open the dialog. Then close it. Move the main window to another screen. Press button again. Popup is now wrong.");
Button b = new Button("Open Dialog");
b.setOnAction(e -> dlg.show());
root.getChildren().add(instructions);
root.getChildren().add(b);
VBox.setMargin(b, new Insets(16, 0, 0, 0));
dlg.setHeight(600);
dlg.setWidth(500);
primaryStage.show();
}
}