By default, when you include one FXML file into another using Scene Builder menu File -> Include -> FXML...
, the included file is added under the root, according the following code:
final FXOMObject rootObject = targetDocument.getFxomRoot();
if (rootObject != null) {
final Selection selection = getEditorController().getSelection();
if (selection.isEmpty() || selection.isSelected(rootObject)) {
targetObject = rootObject;
} else {
targetObject = selection.getAncestor();
}
...
}
In the case of your AnchorWithTabPane.fxml
file, if you don't select anything, it will be included under the root:
<AnchorPane ...>
<children>
<TabPane .../>
<fx:include source="UserControl.fxml" />
</children>
</AnchorPane>
Now, if you select TabPane
, going through the else condition, it will go again under the root, giving that the tabPane's ancestor is the root itself.
If you select Tab
, the ancestor is TabPane
, but there you can't include a FXML node.
If you select the AnchorPane
of a tab, the ancestor is the tab, and you can't include there a FXML node either.
So the solution or workaround in this case is adding some inner container or node to that anchor pane, and then selecting it: since its ancestor will be the AnchorPane
, it will add the FXML node there.
And finally you can delete that temporary container/node.
As a result, you will have:
<TabPane ...>
<tabs>
<Tab text="Untitled Tab 1">
<content>
<AnchorPane ...>
<children>
<fx:include source="UserControl.fxml" />
</children>
</AnchorPane>
</content>
</Tab>
<Tab text="Untitled Tab 2">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</Tab>
</tabs>
Regarding your question about what containers can hold an fx:include
, all the panes under javafx.scene.layout.*
can hold them.
As hint, if you use NetBeans, edit an fxml file, and within the container tags click Ctrl+space, it will show you if the fx:include
node is allowed: