Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.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
将CellValueFactory设置为JavaFX TableColumn中的数据对象_Java_Javafx 2 - Fatal编程技术网

将CellValueFactory设置为JavaFX TableColumn中的数据对象

将CellValueFactory设置为JavaFX TableColumn中的数据对象,java,javafx-2,Java,Javafx 2,我有一个带有自定义单元渲染的tablecolumn此单元渲染将对象作为标签渲染其属性。问题是我找不到将arraylist中的同一对象传递给列的方法。这是我的密码: //I want to render this object in a column as well as use it in the rest of columns CustomerCreationFlow cflow=new CustomerCreationFlow(); cflow.setId(10L);

我有一个带有自定义单元渲染的tablecolumn此单元渲染将对象作为标签渲染其属性。问题是我找不到将arraylist中的同一对象传递给列的方法。这是我的密码:

  //I want to render this object in a column as well as use it in the rest of columns
  CustomerCreationFlow cflow=new CustomerCreationFlow();
        cflow.setId(10L);
        cflow.setFirstName("Feras");
        cflow.setLastName("Odeh");
        cflow.setCustomerType("type");
        ObservableList<CustomerCreationFlow> data = FXCollections.observableArrayList(cflow);
        idclm.setCellValueFactory(new PropertyValueFactory<CustomerCreationFlow, String>("id"));
//I tried this but it didn't work
            flowclm.setCellValueFactory(new PropertyValueFactory<CustomerCreationFlow, CustomerCreationFlow>("this"));
            typeclm.setCellValueFactory(new PropertyValueFactory<CustomerCreationFlow, String>("customerType"));
            flowTable.setItems(data);
//我希望在列中呈现此对象,并在其余列中使用它
CustomerCreationFlow cflow=新CustomerCreationFlow();
cflow.setId(10L);
cflow.setFirstName(“Feras”);
cflow.setLastName(“Odeh”);
cflow.setCustomerType(“类型”);
ObservableList数据=FXCollections.observableArrayList(cflow);
idclm.setCellValueFactory(新属性ValueFactory(“id”);
//我试过了,但没用
flowclm.setCellValueFactory(新的PropertyValueFactory(“本”));
typeclm.setCellValueFactory(新属性ValueFactory(“customerType”);
流程表。设置项目(数据);

有什么建议吗?

您应该通过扩展TableCell来实现自定义CellFactory。 在自定义TableCell中,可以通过获取当前TableCell的TableRow来获取表行的值(逻辑上为CustomerCreationFlow)

这就产生了:

class MyTableCell<S,T> extends TableCell<S, T>

@Override
public void updateItem(final T item, final boolean empty) {
    super.updateItem(item, empty);
    if (empty) {
        this.setText(null);
        this.setGraphic(null);
    } else {
        S item = (S) this.getTableRow().getItem();
        // DO STUFF HERE
    }
}
}
类MyTableCell扩展了TableCell
@凌驾
公共void updateItem(最终T项,最终布尔值为空){
super.updateItem(项,空);
if(空){
this.setText(null);
此.setGraphic(null);
}否则{
S item=(S)this.getTableRow().getItem();
//在这里做事
}
}
}
T是CellValueFactory定义的数据类型。S是表示行的数据类型。

谢谢。this.getTableRow().getItem();这就是我要找的。