Reputation: 159
I am trying to add a new tab with fxml
I am trying this code:
Tab sd=new Tab("Customeradd");
sd.setContent(Source.sourceFor("","Customeradd.fxml"));
tabpanel.getTabs().add(sd);
and i am getting syntax error on line sd.setContent(Source.sourceFor("","Customeradd.fxml"));
and tabpanel
is my TabPane
.
Error Look Like
Help Me please
Upvotes: 1
Views: 4956
Reputation: 13690
Assuming you have a FXML at the same directory as the class where you will load it from, you should do something like this (if your FXML defines a TabPane):
TabPane pane = FXMLLoader.load(this.getClass().getResource("SomeWidget.fxml"));
Now, suppose you have a nice Tab in a MyTab.fxml file:
pane.getTabs().addAll((Tab)FXMLLoader.load(this.getClass().getResource("MyTab.fxml")));
Really easy!
Upvotes: 6