javafx open a new fxml file in new tab dynamically

2019-09-06 14:40发布

I am creating a javafx program in which i need to open a new fxml file in new tab dynamically.

I want that When user click on button a new tab is opened with new fxml file.

I Had no idea I can add tab as per design as much as i need but i want to do it dynamically when user click on button then only a new tab open.

I had also seen Questing but not working for me. Please help me.

Thank you.

2条回答
The star\"
2楼-- · 2019-09-06 14:58

You can add tabs using this code, you need to confirm if your tabPane has this tab or no, else your program invokes SizeOfBounds exception.

if (!MessagePane.getTabs().contains(AllMessageTab)) {
    MessagePane.getTabs().add(AllMessageTab);
}
SingleSelectionModel<Tab> selectionModel = MessagePane.getSelectionModel();
selectionModel.select(AllMessageTab);        
AllMessageTab.setContent(_YourContentNodeHere);
查看更多
forever°为你锁心
3楼-- · 2019-09-06 15:25

You can add tabs dynamically with

myTabPane.getTabs().add(myNewTab);

Create a new Tab with new Tab(), load your FXML and call

myNewTab.setContent(loadedFxmlRoot);
查看更多
登录 后发表回答