One can change the resizeable state of a JavaFX stage using javafx.stage.Stage.setResizable(boolean) method.
QUESTION
Is there any possibility to allow resize only horizontally or only vertically?
There are methods like Stage.setMaxWidth
, Stage.setMaxHeight
, Stage.setMinWidth
, Stage.setMinHeight
but they can only be used to control resizing with fixed sized stages (by setting width = minWidth = maxWidth
for example, to disallow horizontal resizing).
You can prevent external attempts to change height like this:
stage.show();
stage.maxHeightProperty().bind(stage.heightProperty());
stage.minHeightProperty().bind(stage.heightProperty());
Same for width:
stage.maxWidthProperty().bind(stage.widthProperty());
stage.minWidthProperty().bind(stage.widthProperty());
This way will give you the ability to resize it internally when the content changes (call sizeToScene()
for example).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.