Move JavaFX stage to center - Java JavaFX

Java examples for JavaFX:Stage

Description

Move JavaFX stage to center

Demo Code


//package com.java2s;

import javafx.stage.Screen;
import javafx.stage.Stage;

public class Main {
    /**/*w  ww .j  a  v a2 s  .  com*/
     * Move stage to center
     * @param stage
     */
    public static void centerStage(Stage stage) {
        double width = stage.getWidth();
        double height = stage.getHeight();
        stage.setX((Screen.getPrimary().getBounds().getWidth() - width) / 2);
        stage.setY((Screen.getPrimary().getBounds().getHeight() - height) / 2);
    }
}

Related Tutorials