FXML minHeight & minWidth attributs ignored?
Asked Answered
F

2

7

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>
Followup answered 2/5, 2016 at 11:42 Comment(0)
T
4

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);
...
Takeoff answered 2/5, 2016 at 12:32 Comment(1)
Why? Please link to documentation.Budd
U
4

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.

Unmoving answered 6/11, 2017 at 9:53 Comment(1)
This should be the default with JavaFX. I can't understand why it isn't the case.Katheykathi

© 2022 - 2024 — McMap. All rights reserved.