繁体   English   中英

JavaFX:如何使一个表格单元格与另一个表格单元格的值相适应

[英]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 ,它将正确触发表的column2中的更改以及单元格的UI更新。 但由于property1property2均未更改,因此它不会对column1进行任何操作。 如何以某种方式强制column1更改或视情况听取property3的更改

谢谢

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM