我想知道如何从Scene对象添加侦听器或绑定cursorProperty()方法。我试图通过当前光标类型调整场景的大小来检测。
答案 0 :(得分:0)
不是最干净的方法,但它帮助我找出发生了什么:
@Override
public void start(final Stage stage) {
// .. initialize scene
addCursorChangeListeners(mainPane);
scene.cursorProperty().addListener(new ChangeListener<Cursor>() {
@Override
public void changed(final ObservableValue<? extends Cursor> observable, final Cursor oldValue, final Cursor newValue) {
LOGGER.info("Cursor changed for " + scene + " from: " + oldValue + " to: " + newValue);
}
});
}
private void addCursorChangeListeners(final Parent parent) {
for (final Node child : parent.getChildrenUnmodifiable()) {
child.cursorProperty().addListener(new ChangeListener<Cursor>() {
@Override
public void changed(final ObservableValue<? extends Cursor> observable, final Cursor oldValue, final Cursor newValue) {
LOGGER.info("Cursor changed for " + child + " from: " + oldValue + " to: " + newValue);
}
});
if (child instanceof Parent) {
addCursorChangeListeners((Parent) child);
}
}
}
Node
稍后添加的内容不在此处。