Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions javafx-dialogs/src/javafx/scene/control/Dialogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,21 @@ public DialogOptions getDefaultOptions() {
}

private static void centerToOwner(DialogTemplate template) {
final FXDialog dialog = template.getDialog();
FXDialog dialog = template.getDialog();
Window window = dialog.getOwner();

if(!centerToOwner(window, dialog)){
template.getDialog().centerOnScreen();
}
}

private static boolean centerToOwner(Window window, FXDialog inDialog) {
// get center of window
final double windowCenterX = window.getX() + (window.getWidth() / 2);
final double windowCenterY = window.getY() + (window.getHeight() / 2);

final FXDialog dialog = inDialog;

// verify
if(!Double.isNaN(windowCenterX)){
// set a temp position
Expand All @@ -505,13 +513,24 @@ private static void centerToOwner(DialogTemplate template) {
Platform.runLater(new Runnable() {
@Override
public void run() {
dialog.setX(windowCenterX - (dialog.getWidth() / 2));
dialog.setY(windowCenterY - (dialog.getHeight() / 2));
double x = windowCenterX - (dialog.getWidth() / 2);
double y = windowCenterY - (dialog.getHeight() / 2);

// we don't want the top left of the dialog to shoot off the screen
if(x < 0)
x = 0;
if(y < 0)
y = 0;

dialog.setX(x);
dialog.setY(y);
}
});

return true;
}
else {
template.getDialog().centerOnScreen();
return false;
}
}

Expand Down Expand Up @@ -966,7 +985,9 @@ private List<Button> createButtons() {
Button detailsBtn = new Button((detailBtnStr == null) ? "" : getMessage(detailBtnStr));
detailsBtn.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent ae) {
new ExceptionDialog(dialog, throwable).show();
ExceptionDialog dia = new ExceptionDialog(dialog, throwable);
centerToOwner(dialog, dia);
dia.show();
}
});
buttons.add(detailsBtn);
Expand Down