center Dialog along with JavaFX Stage - Java JavaFX

Java examples for JavaFX:Dialog

Description

center Dialog along with JavaFX Stage

Demo Code


//package com.java2s;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class Main {
    public static void center(Stage parent, Stage dialog) {
        Pane root = (Pane) dialog.getScene().getRoot();
        double dialogX = parent.getX() + (parent.getWidth() / 2)
                - root.getPrefWidth() / 2;
        double dialogY = parent.getY() + (parent.getHeight() / 2)
                - root.getPrefHeight() / 2;
        dialog.setX(dialogX);//from  w  ww.ja  v a 2  s  .  com
        dialog.setY(dialogY);
    }
}

Related Tutorials