本文介绍了如何在JavaFX中监听大小调整事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在JavaFX 2.1中检测场景或舞台何时更改大小?我为此找不到任何EventHandler.
How can I detect when a Scene or Stage changes size in JavaFX 2.1? I cannot find any EventHandler for this.
推荐答案
有heightProperty
和widthProperty
.您可以使用这些属性进行绑定,也可以向其添加侦听器.
There are heightProperty
and widthProperty
. You can use these properties for binding, or add listeners to them.
public void start(Stage stage) {
Scene scene = new Scene(new Group(), 300, 200);
stage.setScene(scene);
stage.titleProperty().bind(
scene.widthProperty().asString().
concat(" : ").
concat(scene.heightProperty().asString()));
stage.show();
}
或查看下一个示例: https://stackoverflow.com/a/9893911/1054140
这篇关于如何在JavaFX中监听大小调整事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!