我试图用JavaFX在Java中创建多个TableView。 我有一个Controller和一个FXML文件。如果我从中创建多个表 相同的FXML我得到相同的内容。是否可以创建多个 TableViews有不同的内容?
这就是现在的样子:
MainApp
/**
* CreateAndShowTable
*/
public void CreateAndAddTable() {
try {
getNextTableData(); // Here i change the Data
// Load person overview.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource(url));
tableList.add((TableView) loader.load());
// Sets the TableViews, only 3 in one Row
if(colIndex % 3 == 0){
rowIndex++;
colIndex = 0;
}
tablePane.add(tableList.get(tableList.size()-1), rowIndex, colIndex);
colIndex ++;
// Give the controller access to the main app.
TableViewController controller = loader.getController();
controller.setMainApp(this);
} catch (IOException e) {
e.printStackTrace();
}
}
TableViewController:
/**
* Is called by the main application to give a reference back to itself.
*
* @param mainApp
*/
public void setMainApp(MainApp mainApp) {
this.mainApp = mainApp;
// Add observable list data to the table
dataTable.setItems(mainApp.getTableData());
}