JavaFX How to set max / min window size?

Does setMinSize () work on containers like GridPane? I found that in my program GridPane ignores mines. when resizing manually. Here is the FXML code:

<GridPane fx:id="gp" prefHeight="134.0" prefWidth="238.0" xmlns:fx="http://javafx.com/fxml" fx:controller="javafxapplication12.SampleController"> <columnConstraints> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> </columnConstraints> <rowConstraints> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> </rowConstraints> </GridPane> 

and controller class

 public class SampleController implements Initializable { @FXML private GridPane gp; @Override public void initialize(URL url, ResourceBundle rb) { gp.setMaxWidth(700); gp.setMinSize(200, 200); } 

What is wrong here? Should there be some kind of "maximum / minimum" window size?

+7
source share
1 answer

I'm going to assume that by window you mean Stage (in this subclass of Window).

The window size may differ from the size of the root container for the scene. You can present a window or scene as an independent viewport into a scene, the size of which can be larger or smaller than the minimum and maximum characteristics of the root of the scene.

To set the minimum or maximum size of the scene, set minHeight and minWidth or maxHeight and maxWidth .

Answers to additional questions

Can the scene be set to "fit whole display"?

stage.setFullScreen(true)

But how to make the size the same as we do the size by clicking on the title bar?

stage.setMaximized(true)

+18
source

All Articles