我对JavaFX中的TableView有问题。
从定义了所有字段的现有类创建表很容易。
但是我想知道是否有可能制作表格并从列表中添加数据?
我做了这样的东西,但它有点不起作用。
@FXML
private TableView<List<String>> testTable;
....
List<String> list = new ArrayList<>();
list.add("1hello");
list.add("1hello2");
List<String> list2 = new ArrayList<>();
list2.add("2hello");
list2.add("2hello2");
ObservableList<List<String>> lists = FXCollections.observableArrayList();
lists.add(list);
lists.add(list2);
TableColumn<List<String>, String> coll = new TableColumn<>("one");
coll.setCellValueFactory(new PropertyValueFactory<List<String>,String>(""));
TableColumn<List<String>, String> coll2 = new TableColumn<>("two");
coll2.setCellValueFactory(new PropertyValueFactory<List<String>,String>(""));
testTable.getColumns().add(coll);
testTable.getColumns().add(coll2);
lists.forEach(li -> {
System.out.println("list: " + li);
testTable.getItems().add(li);
}); 它没有插入任何数据。这样的事情有可能发生吗?
https://stackoverflow.com/questions/46171183
复制相似问题