center JavaFX Stage - Java JavaFX

Java examples for JavaFX:Stage

Description

center JavaFX Stage

Demo Code


//package com.java2s;

import javafx.geometry.Rectangle2D;

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

public class Main {
    public static void centerStage(Stage stage) {
        Rectangle2D primScreenBounds = Screen.getPrimary()
                .getVisualBounds();/*from   w ww.java2s  . c o m*/
        stage.setX((primScreenBounds.getWidth() - stage.getWidth()) / 2);
        stage.setY((primScreenBounds.getHeight() - stage.getHeight()) / 2);
    }
}

Related Tutorials