set JavaFX Window Location - Java JavaFX

Java examples for JavaFX:Stage

Description

set JavaFX Window Location

Demo Code


import javafx.application.Platform;
import javafx.stage.Stage;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Main{
    public static void setWindowLocation(Stage stage, Stage owner,
            WindowLocation location) {/*from w ww . j a  v a2 s.c  om*/
        if (location == WindowLocation.CENTER_OWNER) {
            stage.setX(owner.getX() + owner.getWidth() / 2
                    - stage.getWidth() / 2);
            stage.setY(owner.getY() + owner.getHeight() / 2
                    - stage.getHeight() / 2);
        }
        if (location == WindowLocation.CENTER_SCREEN) {
            stage.centerOnScreen();
        }
    }
}

Related Tutorials