Calculate preferred size and set as minimum

Miroslav Nachev mnachev.nscenter.eu at gmail.com
Thu Aug 23 14:34:30 UTC 2018


Hi,

Is there any standard way to calculate the preferred size for Scene,
Node/Pane and Stage/Window?
I want once a form/pane is visualized, it cannot be minimized to a certain
size. Since I did not find such a built-in opportunity, at the moment I am
doing the following:

        Scene scene = new Scene(gridPane);
        primaryStage.setScene(scene);
        primaryStage.sizeToScene();

        primaryStage.show();
        primaryStage.setMinWidth(primaryStage.getWidth() + 1);
        primaryStage.setMinHeight(primaryStage.getHeight() + 1);
        primaryStage.setWidth(640);
        primaryStage.setHeight(480);
        primaryStage.show();

The first call to primaryStage.show() (in orange) I do to calculate the
minimum panel size (Scene/GridPane), then set that size as minimum on
primaryStage, and finally set the size I want and visualize the panel again.

The unpleasant side effect is, that the panel is no longer at the center of
the screen.

Any ideas?


Regards,
Miro.


More information about the openjfx-dev mailing list