I had the same problem and couldn't make it work in any suggested way, but what did the trick for me, if we instantiate columns and have nested property, for instance, in class Employee:
@FXML
private TableColumn<Employee, String> columnEmpName;
@FXML
private TableColumn<Employee, String> columnEmpLastName;
@FXML
private TableColumn<Employee, String> columnEmpJobDesc;
And class is:
public class Employee {
private String name;
private String lastName;
.
.
private EmployeeJobDescription jobDesc; //this one is nested
}
I have made ObservableValue<String> out of string I picked up for that property
columnEmpName.setCellValueFactory(new PropertyValueFactory<Employee, String>("name"));
columnEmpLastName.setCellValueFactory(new PropertyValueFactory<Employee, String>("lastname"));
columnEmpJobDesc.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getJobDesc().getJobDescription()));
And the EmployeeJobDescription would be with all getters and setters
public class EmployeeJobDescription {
private Integer id;
private String jobDescription;
public EmployeeJobDescription(Integer id) {
this.id = id;
}
public EmployeeJobDescription(Integer id, String jobDescription) {
this.id = id;
this.jobDescription = jobDescription;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getJobDescription() {
return jobDescription;
}
public void setJobDescription(String jobDescription) {
this.jobDescription = jobDescription;
}
}
Found out how to do that in this post:
Convert a String to an ObservableValue