I\'m testing myself with a simple CSV Viewer using JavaFX and I\'m stuck at populating the table data. I do create the columns dynamically, but the data values are a no-go.
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 dataList : data) {
table1.setItems(dataList); // Requires an ObservableList!
}
with
// which will make your table view dynamic
ObservableList csvData = FXCollections.observableArrayList();
for(List dataList : data) {
ObservableList 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