I\'ve got problem with TableView in JavaFX.
Creating tables from existing class with all fields defined is easy.
But I\'m wondering if it is possible to make
You can do this by replacing String
to StringProperty
in the List
:
@FXML
private TableView> testTable;
then:
TableColumn, String> coll = new TableColumn<>("one");
add the cellValueFactories:
col1.setCellValueFactory(data -> data.getValue().get(0));
col2.setCellValueFactory(data -> data.getValue().get(1));
.
.
and so on.
This means the first element of the list will be used in col1
, the second element of the list will be used in col2
.
Then you can populate the list like:
ObservableList> data = FXCollections.observableArrayList();
List firstRow = new ArrayList<>();
firstRow.add(0, new SimpleStringProperty("Andrew"));
firstRow.add(1, new SimpleStringProperty("Smith"));
.
.
.
data.add(firstRow);
.
.
.
and so on...
table.setItems(data);
It is doable this way but I would say it is a very bad practice.