在这个问题上,我需要您的帮助,因为我希望包含来自不同包的子fxml。如果两个位置相同,我可以将child.fxml包含到parent.fxml中,但当两者处于不同的位置/包时,我不知道如何将child.fxml添加到parent.fxml中。
提前谢谢。
发布于 2013-07-27 02:29:49
对子FXML文件的访问应该是通过相对路径,从FXML文档:
其中文件名是要包含的FXML文件的名称。以前导斜杠字符开头的值被视为相对于类路径的值。没有前导斜杠的值被视为相对于当前文档的路径。
示例:
org.tarrsalah.includefxml
|
|__childview
| |_________child.fxml
|
|__mainview
|_________main.fxmlmain.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>访问父目录的..,childview,然后是child.fxml。
https://stackoverflow.com/questions/17879988
复制相似问题