Set stage x and y according to screen size : screen « JavaFX « Java

Set stage x and y according to screen size


import javafx.application.Application;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Screen;
import javafx.stage.Stage;

public class Main extends Application {

    public void start(Stage stage) {
        Text text = new Text("!");
        text.setFont(new Font(40));
        VBox box = new VBox();
        final Scene scene = new Scene(box,300, 250);

        Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds();
        stage.setX((primScreenBounds.getWidth() - stage.getWidth()) / 2); 
        stage.setY((primScreenBounds.getHeight() - stage.getHeight()) / 4);  

    public static void main(String[] args) {


Related examples in the same category

1.Get Screen size