Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFX:一个表列中有两个值_Java_Javafx_Lambda_Tableview - Fatal编程技术网

JavaFX:一个表列中有两个值

JavaFX:一个表列中有两个值,java,javafx,lambda,tableview,Java,Javafx,Lambda,Tableview,我有一个follower,在TableColumn中有一个使用lambdas设置值的代码: firstNameColumn.setCellValueFactory(cellData -> cellData.getValue().firstNameProperty()); lastNameColumn.setCellValueFactory(cellData -> cellData.getValue().lastNameProperty()); 但是,如果我有一个列全名,并且想将fi

我有一个follower,在TableColumn中有一个使用lambdas设置值的代码:

firstNameColumn.setCellValueFactory(cellData -> cellData.getValue().firstNameProperty());
lastNameColumn.setCellValueFactory(cellData -> cellData.getValue().lastNameProperty());
但是,如果我有一个列全名,并且想将firstnamecomment和lastnamecomment合并成一个全名,该怎么办呢


谢谢你的回答。

愚蠢的代码有效:

fullNameColumn.setCellValueFactory(cellData -> cellData.getValue().firstNameProperty() + " " + cellData.getValue().lastNameProperty());

愚蠢的代码起作用:

fullNameColumn.setCellValueFactory(cellData -> cellData.getValue().firstNameProperty() + " " + cellData.getValue().lastNameProperty());

这可以通过创建同时依赖于名字和姓氏的StringBinding来实现:

fullNameColumn.setCellValueFactory(cellData -> Bindings.createStringBinding(
    () -> cellData.getValue().getLastName() + ", " + cellData.getValue().getFirstName(),
    cellData.getValue().firstNameProperty(),
    cellData.getValue().lastNameProperty()
));

这可以通过创建同时依赖于名字和姓氏的StringBinding来实现:

fullNameColumn.setCellValueFactory(cellData -> Bindings.createStringBinding(
    () -> cellData.getValue().getLastName() + ", " + cellData.getValue().getFirstName(),
    cellData.getValue().firstNameProperty(),
    cellData.getValue().lastNameProperty()
));

或者cellData->cellData.getValue.firstNameProperty.concat、.concatcellData.getValue.lastNameProperty不确定这是否更干净…如何在第三列中添加两列?列使用SimpleIntegerProperty绑定。我尝试了相同的代码,只替换为Bindings.createIntegerBinding。我正在寻找一个示例,但找不到它。或者cellData->cellData.getValue.firstNameProperty.concat、.concatcellData.getValue.lastNameProperty不确定这是否更干净…如何在第三行中添加两列?列使用SimpleIntegerProperty绑定。我尝试了相同的代码,只替换为Bindings.createIntegerBinding。我正在寻找一个例子,但我找不到。对不起,这段代码实际上不正确。法比安的答案是好的,那是编译吗?lambda表达式的计算结果是一个字符串:您需要一个observeValue。是的,您是对的。我有不同的项目,采用不同的方法tá和以下编译,但这是不同的故事fullNameColumn.setCellValueFactorycellData->new SimpleStringProperty cellData.getValue.firstName++cellData.getValue.lastName;:是的,这会起作用,但如果其中一个属性发生更改,它不会自动更新…另一个项目不使用Person模型中的属性,因此,我必须将字符串转换为controller中的属性。这个项目的问题是,有一半不是我的,但是我写的购买第三方和模型人是为JavaFX设计的。对不起,这段代码实际上是不对的。法比安的答案是好的,那是编译吗?lambda表达式的计算结果是一个字符串:您需要一个observeValue。是的,您是对的。我有不同的项目,采用不同的方法tá和以下编译,但这是不同的故事fullNameColumn.setCellValueFactorycellData->new SimpleStringProperty cellData.getValue.firstName++cellData.getValue.lastName;:是的,这会起作用,但如果其中一个属性发生更改,它不会自动更新…另一个项目不使用Person模型中的属性,因此,我必须将字符串转换为controller中的属性。这个项目的问题是,它的一半不是我的,而是为javafx设计的书面购买第三方和模型人