问题
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
回答1:
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!
来源:https://stackoverflow.com/questions/24850050/javafx-adding-new-tab-with-fxml-on-click