use DataFX,which will make your job easier :)
Example Code :
DataSourceReader dsr1 = new FileSource("your csv file path");
String[] columnsArray // create array of column names you want to display
CSVDataSource ds1 = new CSVDataSource(dsr1,columnsArray);
TableView tableView = new TableView();
tableView.setItems(ds1.getData());
tableView.getColumns().addAll(ds1.getColumns());
Reference : Introduction to DataFX
Edit :
Standard JavaFX Way
replace your code :
for(List<String> dataList : data) {
table1.setItems(dataList); // Requires an ObservableList!
}
with
// which will make your table view dynamic
ObservableList<ObservableList> csvData = FXCollections.observableArrayList();
for(List<String> dataList : data) {
ObservableList<String> row = FXCollections.observableArrayList();
for( String rowData : dataList) {
row.add(rowData);
}
cvsData.add(row); // add each row to cvsData
}
table1.setItems(cvsData); // finally add data to tableview
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…