user3505901
user3505901

Reputation: 408

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

Upvotes: 0

Views: 173

Answers (1)

Prometheus
Prometheus

Reputation: 1015

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

Upvotes: 2

Related Questions