如果值为 null 且包含选定值,则禁用组合框

sya*_*qah 2 lambda combobox javafx java-8

我有两个组合框示例组合框 a 和 b。当comboBox an 为空并且从comboBox a 中选择特定值时,我想禁用comboBox b。

comboboxb.disableProperty().bind(
        JavaFxObserver.toBinding(
        JavaFxObservable.nullableValuesOf(comboboxa.getSelectionModel().selectedItemProperty())
            .map(test -> !comboboxaEnum.isPresent() || comboboxaEnum.equals(comboboxaEnum.XX) ))
    );
Run Code Online (Sandbox Code Playgroud)

只有在 comboBox 为空时才禁用。

Ser*_*nev 5

如果需要检查两个条件,则使用Bindings逻辑运算:

comboBoxB.disableProperty().bind(
    Bindings.or(
       Bindings.equal(comboBoxA.getSelectionModel().selectedItemProperty(), "Value Which Disables"),
       Bindings.isNull(comboBoxA.getSelectionModel().selectedItemProperty())
));
Run Code Online (Sandbox Code Playgroud)