Java FX 绑定:绑定布尔属性的动态列表
Java FX Bindings: bind a dynamic list of boolean properties
我正在尝试为我的 CustomPane
创建一个 BooleanProperty
,我们称它为 isEmpty
。
当 TextField
个对象的集合(在运行时填充)符合条件时,属性 应该是 true。 此列表内容一经提供便不会更改。
在这种情况下,条件是所有字段都必须为空(任何字段中都没有文本)。
因此,当构建 CustomPane
对象时,我有字段列表,我应该将它们的所有 .textProperty().isEmpty()
绑定在一起。
关于如何执行此操作的任何建议?
你可以这样做:
private BooleanBinding areTheyEmptyBinding(List<TextField> list){
BooleanBinding bind = new SimpleBooleanProperty(false).not();
for (TextField text: list)
bind = bind.and(text.textProperty().isEmpty());
return bind;
}
我正在尝试为我的 CustomPane
创建一个 BooleanProperty
,我们称它为 isEmpty
。
当 TextField
个对象的集合(在运行时填充)符合条件时,属性 应该是 true。 此列表内容一经提供便不会更改。
在这种情况下,条件是所有字段都必须为空(任何字段中都没有文本)。
因此,当构建 CustomPane
对象时,我有字段列表,我应该将它们的所有 .textProperty().isEmpty()
绑定在一起。
关于如何执行此操作的任何建议?
你可以这样做:
private BooleanBinding areTheyEmptyBinding(List<TextField> list){
BooleanBinding bind = new SimpleBooleanProperty(false).not();
for (TextField text: list)
bind = bind.and(text.textProperty().isEmpty());
return bind;
}