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


Question

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?

1
8
3/20/2014 1:49:40 PM

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.

2
3/20/2014 1:08:09 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon