Dil
Dil

Reputation: 618

How to include child fxml inside parent fxml

I need your help with this problem where i want to include child fxml from different package. I am able to include child.fxml into parent.fxml if both are in same location, but don't know how to add a child.fxml into parent.fxml when both are in diffrent location/package.

Thanks in advance.

Upvotes: 1

Views: 2384

Answers (1)

Salah Eddine Taouririt
Salah Eddine Taouririt

Reputation: 26395

Accessing to child FXML files should be via relative path, from the FXML docs :

where filename is the name of the FXML file to include. Values that begin with a leading slash character are treated as relative to the classpath. Values with no leading slash are considered relative to the path of the current document.

Example:

org.tarrsalah.includefxml
  |
  |__childview
  |    |_________child.fxml
  |
  |__mainview
       |_________main.fxml

main.fxml

<StackPane id="mainView"  xmlns:fx="http://javafx.com/fxml" fx:controller="org.tarrsalah.includefxml.mainview.MainController">
    <children><fx:include source="../childview/child.fxml"/></children>        
</StackPane>

.. to access to the parent directory,childview, and then child.fxml .

Upvotes: 1

Related Questions