How to dynamically change the height of a stage in JavaFx

风格不统一 提交于 2020-01-15 12:39:08

问题


Is it possible to create a Stage in JavaFx whose height changes dynamically? Or, in other words, is it possible to change the height of a Stage once it has been created (stage.show()), so that the stage morph's into its new height?


回答1:


Use stage.sizeToScene() to resize the stage to whatever the current preferred size of it's root is.

 stage.setScene(new Scene(someContent));
 stage.show();
 ....
 stage.getScene().setRoot(someNewContent));
 stage.sizeToScene();

You can also just call stage.setWidth() or stage.setHeight() if you don't need the automatic sizing behavior of sizeToScene().

You can use a Timeline to animate the stage size change if you need to do that.



来源:https://stackoverflow.com/questions/31360919/how-to-dynamically-change-the-height-of-a-stage-in-javafx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!