简体   繁体   中英

javafx open a new fxml file in new tab dynamically

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM