问题描述
我刚刚开始我的第二个JavaFX项目,我需要知道何时最大化Stage
.在Swing中,这非常简单,可以通过使用WindowListener/Event来完成.但是,在搜索了JavaFX的Javadoc之后,我似乎找不到任何监听Stage
状态的方法.
I am just starting my second JavaFX projects, and I need to know when a Stage
is being maximized. In Swing, this is fairly simple and can be accomplished by using a WindowListener/Event. However, after searching through JavaFX's Javadoc, I can't seem to find any way of listening to the state of a Stage
.
有没有办法做到这一点?
Is there any way to do this?
推荐答案
要了解Stage
是否已最小化,可以收听iconified
属性:
To find out if Stage
minimized you can listen to iconified
property:
stage.iconifiedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
System.out.println("minimized:" + t1.booleanValue());
}
});
在即将发布的8.0版本中添加了
通讯员maximized
属性:
Correspondent maximized
property is added in the upcoming 8.0 release:
stage.maximizedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
System.out.println("maximized:" + t1.booleanValue());
}
});
您可以在此处下载JDK 8(包括FX8)的早期访问版本: http://www.oracle.com/technetwork/java/javase/downloads/ea-jsp-142245.html
You can download early access build of JDK 8 (which includes FX8) here: http://www.oracle.com/technetwork/java/javase/downloads/ea-jsp-142245.html
这篇关于侦听器,用于最小化,最大化等舞台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!