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>
Jeankowkow
  • 814
  • 13
  • 33

2 Answers2

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);
...
fabian
  • 80,457
  • 12
  • 86
  • 114
7twenty7
  • 558
  • 1
  • 3
  • 16
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.

xeruf
  • 2,602
  • 1
  • 25
  • 48