JavaFX/Controlsfx - 如何监控 PropertySheet 中的项目变化?
JavaFX/Controlsfx - How to monitor item change in a PropertySheet?
有没有方便的方法来监控 属性 工作表项状态?像文本字段获得焦点、布尔状态更改等。
我看过 javadoc,没找到。
这里还有一个issue,不过解法好像让小编知道了一个属性的变化。
我要的恰恰相反,监督小编
有人可以帮忙吗?
来自 PropertySheet:
/**
* Sets a new editor factory used by the PropertySheet to determine which
* {@link PropertyEditor} to use for a given {@link Item}.
* @param factory
*/
public final void setPropertyEditorFactory( Callback<Item, PropertyEditor<?>> factory ) {
propertyEditorFactory.set( factory == null? new DefaultPropertyEditorFactory(): factory );
}
如果您创建 PropertyEditor 的回调,您可以向编辑器添加侦听器。
例如:
SimpleObjectProperty<Callback<PropertySheet.Item, PropertyEditor<?>>> propertyEditorFactory = new SimpleObjectProperty<>(this, "propertyEditor", new DefaultPropertyEditorFactory());
projectSheet.setPropertyEditorFactory(getItemPropertyEditorCallback(propertyEditorFactory));
private Callback<PropertySheet.Item, PropertyEditor<?>> getItemPropertyEditorCallback(SimpleObjectProperty<Callback<PropertySheet.Item, PropertyEditor<?>>> propertyEditorFactory) {
return param -> {
PropertyEditor<?> editor = propertyEditorFactory.get().call(param);
//Add listeners to editor
editor.getEditor().focusedProperty().addListener((observable, oldValue, newValue) -> System.out.println(newValue));
return editor;
};
}
有没有方便的方法来监控 属性 工作表项状态?像文本字段获得焦点、布尔状态更改等。
我看过 javadoc,没找到。
这里还有一个issue,不过解法好像让小编知道了一个属性的变化。
我要的恰恰相反,监督小编
有人可以帮忙吗?
来自 PropertySheet:
/**
* Sets a new editor factory used by the PropertySheet to determine which
* {@link PropertyEditor} to use for a given {@link Item}.
* @param factory
*/
public final void setPropertyEditorFactory( Callback<Item, PropertyEditor<?>> factory ) {
propertyEditorFactory.set( factory == null? new DefaultPropertyEditorFactory(): factory );
}
如果您创建 PropertyEditor 的回调,您可以向编辑器添加侦听器。
例如:
SimpleObjectProperty<Callback<PropertySheet.Item, PropertyEditor<?>>> propertyEditorFactory = new SimpleObjectProperty<>(this, "propertyEditor", new DefaultPropertyEditorFactory());
projectSheet.setPropertyEditorFactory(getItemPropertyEditorCallback(propertyEditorFactory));
private Callback<PropertySheet.Item, PropertyEditor<?>> getItemPropertyEditorCallback(SimpleObjectProperty<Callback<PropertySheet.Item, PropertyEditor<?>>> propertyEditorFactory) {
return param -> {
PropertyEditor<?> editor = propertyEditorFactory.get().call(param);
//Add listeners to editor
editor.getEditor().focusedProperty().addListener((observable, oldValue, newValue) -> System.out.println(newValue));
return editor;
};
}