You can do this by replacing String
to StringProperty
in the List
:
@FXML
private TableView<List<StringProperty>> testTable;
then:
TableColumn<List<StringProperty>, 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<List<StringProperty>> data = FXCollections.observableArrayList();
List<StringProperty> 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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…