JavaFX:如何使 Table 单元格取决于另一个 Table 单元格的值

JavaFX: How to make a Table Cell to be contigent to the value of another Table Cell

我有一个非常简单的模型,由 3 个 StringProperty 组成,我们称它们为 property1property2property3。我在我的模型中定义了常用的 get/set/property 方法。我现在使用 TableView 来显示其中的一些属性。 Column模型定义如下

TableColumn<MyModel, String> tableColumn1 = new TableColumn<MyModel, String>("display 1");
TableColumn<MyModel, String> tableColumn2 = new TableColumn<MyModel, String>("display 2");

现在 TableColumn 遵循使用链接到我模型的 属性 之一的单元格值工厂的模式。

tableColumn1.setCellValueFactory((t)-> {
                MyModel myModelValue  = ((MyModel)t.getValue());    
                return myModelValue.getProperty3().equals("something") ? property1():property2();
            });

tableColumn2.setCellValueFactory((t)-> property3());

现在的问题如下。如果 property3 在执行期间某处发生更改,它将正确触发我的 table 的 column2 的更改和单元格的 UI 更新。但它不会为 column1 做任何事情,因为 property1property2 都没有改变。我怎样才能以某种方式强制 column1 改变或偶然地听取 property3

的变化

谢谢

tableColumn1.setCellValueFactory(t -> {
    MyModel myModelValue = t.getValue();
    return Bindings.when(myModelValue.property3().equals("something"))
        .then(myModelValue.property1())
        .otherwise(myModelValue.property2());
});