javafx open a new fxml file in new tab dynamically

混江龙づ霸主 提交于 2019-12-12 02:45:06

问题


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.


回答1:


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);



回答2:


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);


来源:https://stackoverflow.com/questions/24598692/javafx-open-a-new-fxml-file-in-new-tab-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!