How to set the minimum window size according to its contents in JavaFX?

To statically set the minimum window size to a frame of 100x100 pixels in JavaFX 2.2, you should use:

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

Suppose we don’t want to set a fixed minimum size, but we want the window to be resized to a minimum size, and all its contents (buttons, text fields, etc.) are still fully visible. How do we do this?

+8
java javafx
source share
2 answers

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

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

Resizing children will change the binding expression and change the minWidthProperty property on your scene.

+2
source share

I suggest you read the javadoc Pane , Region and possibly Group nodes. About how they plan and resize their children. In principle, if you do not set a preferred panel size, then by default it will be calculated according to its contents. Also see the Window.sizeToScene () method .

0
source share

All Articles