实现 JavaFX ObservableValue 接口的正确方法
Correct way to implement JavaFX ObservableValue interface
正在寻找实现 ObservableBooleanValue
的正确方法,这将取决于 StringPropertyValue
。用于与按钮的 disableProperty
.
绑定
没有必要自己实现接口。您可以使用 the createBooleanBinding
method of the Bindings
utility class:
BooleanBinding binding = Bindings.createBooleanBinding(new Callable<Boolean>() {
@Override
public Boolean call() {
return theStringProperty.get().contains("42");
}
}, theStringProperty);
someNode.disableProperty().bind(binding);
如果 theStringProperty
包含以 42
作为子字符串的值,上述代码将禁用 someNode
。
正在寻找实现 ObservableBooleanValue
的正确方法,这将取决于 StringPropertyValue
。用于与按钮的 disableProperty
.
没有必要自己实现接口。您可以使用 the createBooleanBinding
method of the Bindings
utility class:
BooleanBinding binding = Bindings.createBooleanBinding(new Callable<Boolean>() {
@Override
public Boolean call() {
return theStringProperty.get().contains("42");
}
}, theStringProperty);
someNode.disableProperty().bind(binding);
如果 theStringProperty
包含以 42
作为子字符串的值,上述代码将禁用 someNode
。