简体   繁体   中英

How to add a new tab using FXML?

I'm really lost as to how to add tabs in FXML and Java using my controller class, can someone take a look and tell me how it'd be done?

Here's my main class: http://pastebin.com/mHkqYe5D Here's my fxml class: http://pastebin.com/pHLJJRWp Here's my controller class: http://pastebin.com/dp0Yb5Eg

Your code for adding the tab looks fine.

public Tab tab = new Tab();

public void menuItemNewTab(ActionEvent event){
        tabPane.getTabs().add(tab);
}

However, you seem to be trying to add the same Tab object with each click. I did a quick test and I think that is your problem. Create a new instance every time you add a new Tab:

public void menuItemNewTab(ActionEvent event){
        tabPane.getTabs().add(new Tab());
}

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