I am basically new to JavaFX and I started my first project in it. First of all I want to ensure you that I have read articles linked below:
JavaFx TabPane : One controller per Tab JavaFX Pane inside of a Tab
I know how to put Pane directly into the Tab, but what I want is to have each Controller for every content inside Tabs in my TabPane.
Main.fxml
<center>
<TabPane fx:id="mainTabPane">
<tabs>
<Tab fx:id="tabChar" closable="false" text="Character" onSelectionChanged="#showCharacterTab"/>
<Tab fx:id="tabSkills" closable="false" text="Skills" />
<Tab fx:id="tabMagic" closable="false" text="Magic" />
<Tab fx:id="tabStory" closable="false" text="Story" />
<Tab fx:id="tabPortrait" closable="false" text="Portrait" />
<Tab fx:id="tabDatabase" closable="false" text="Char-Base" />
</tabs>
</TabPane>
</center>
What I have to mention that my TabPane is located in the center of BorderPane, which is a Main Window.
I tried to build new Scene for that tab and associate it withing showCharacterTab method, but at the moment I ended up with this:
@FXML
private Tab tabChar;
@FXML
public void showCharacterTab() throws IOException{
if (tabChar.isSelected()) {
AnchorPane characterPane = FXMLLoader.load(getClass().getResource("character.fxml"));
tabChar.setContent(characterPane.getParent());
}
}
And for now I'm totally clueless how to do it. I am a newbie and I started probably with too much content. I don't know if I have to put it in initialize() method to make it visible at start and I don't know if I use correctly onSelectionChanged method.
So to sum up: I want to make every content in different tabs associated with new FXML file and new Controller. I tried to do it avoiding Nested Controllers option described here: Nested Controllers