FXML minHeight & minWidth attributs ignored?

5.9k Views Asked by At

How can I set a minimum size to my window ? I try to set the minHeight minWidth value but I can still resize the Window under this values with the mouse.

Here is my FXML root pane:

<BorderPane fx:id="borderPane"
        minHeight="200" minWidth="400" prefHeight="600" prefWidth="800"
        xmlns="http://javafx.com/javafx/null"
        xmlns:fx="http://javafx.com/fxml/1"
        fx:controller="simulation.Simulation_Controller">
</BorderPane>
2

There are 2 best solutions below

1
On BEST ANSWER

To do so you have to set the minHeight and minWidth of your Stage.

Somewhere in your java code...:

Example:

...
yourStage.setMinHeight(480);
yourStage.setMinWidth(640);
...
1
On

Here is a simple, working solution:

Parent root = FXMLLoader.load(getClass().getResource("/your/layout.fxml"));

stage.setMinWidth(root.minWidth(-1));
stage.setMinHeight(root.minHeight(-1));

This sets the minimum size of your stage to the values defined in the top-level element of the FXML-File, or 0 if they are not defined.