I want to display all Prisoners data into a single TableView. A prisoner looks like that (all the code is a sample) :
public class Prisoner {
private String id;
private String name;
private PrisonerCase case;
Prisoner() {
id = "Unknown";
name = "Unknown";
case = new PrisonerCase();
}
}
public class PrisonerCase {
private String id_case;
private String date_case;
PrisonerCase() {
id_case = "unknown";
date_case = "unknown";
}
}
Then I have my TableView :
data is an ObservableList<Prisoner> and return all the prisoners I have in my database. I build all prisoners and all the prisoner cases in the function getData().
TableView tv = new TableView();
data = Database.getData();
TableColumn id_column = new TableColumn("ID");
id_column.setCellValueFactory(new PropertyValueFactory<Prisoner, String>("id"));
This works fine, but my question is, how can I add the case in the TableView ? I tried
TableColumn n_case_column = new TableColumn("N° Case");
n_case_colmun.setCellValueFactory(new PropertyValueFactory<PrisonerCase, String>("id_case"));
But it doesn't work. Of course, I didn't forget to add all the columns to the TableView at the end.
tv.setItems(data);
tv.getColmuns().addAll(id_column, n_case_column);
tv.getColmuns().addAll(id_column, n_case_column); tv.setItems(data);Also you should specify columns type such asTableColumn<Prisoner,String> columnName- Anas