Marco Lackovic
Marco Lackovic

Reputation: 6497

How to set a window minimum size according to its content in JavaFX?

To statically set a window minimum size to a 100x100 pixels frame in JavaFX 2.2 one would use:

stage.setMinWidth(100);
stage.setMinHeight(100);

Supposing we don't want to set a fixed minimum size, but we want the window to be resized to a minimum size that all its content (buttons, text fields, etc.) is still fully visible. How would we do that?

Upvotes: 8

Views: 5685

Answers (2)

Uluk Biy
Uluk Biy

Reputation: 49185

I suggest you to read the javadoc of Pane, Region and maybe Group nodes. On how they layout and resize their children. Basically if you don't set the preferred size of the pane then, by default, it will be calculated according to its content. Also have a look on Window.sizeToScene() method.

Upvotes: 1

zenbeni
zenbeni

Reputation: 7193

You can try to use stage.minWidthProperty().bind(... Binding expression here...);

The difficulty of course is to define the binding expression... it should depend on all your components but still it should work.

Resizing children will modify the binding expression and will change the minWidthProperty on your Stage.

Upvotes: 2

Related Questions