如何在JavaFx中动态更改舞台的高度 [英] How to dynamically change the height of a stage in JavaFx

查看:100
本文介绍了如何在JavaFx中动态更改舞台的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在JavaFx中创建一个高度动态变化的舞台?或者换句话说,一旦创建了舞台,就可以更改其高度(stage.show()),以使舞台变形变为新的高度吗?

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?

推荐答案

使用

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();

您也可以只调用 stage .setWidth()或stage.setHeight()(如果不需要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.

这篇关于如何在JavaFx中动态更改舞台的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆