使用FXML加载Gluon布局。
我想以与文档不同的方式加载布局: https://docs.gluonhq.com/charm/5.0.1/#_layers
区别在于我想用FXMLLoader加载它。
我的代码类似于以下示例:
扩展MobileApplication的类
@Override
public void init() {
addViewFactory("VIEW",HomeViewLoader::new);
addLayerFactory("LAYER",LayerLoader::new);
}
Class LayerLoader扩展了层 -我想使用此类加载FXML
public LayerLoader(){
FXMLLoader loader = new FXMLLoader(getclass().getResource(fxmlPath));
Parent root = null;
try {
root = loader.load(); //exception in this line
} catch (IOException e) {
e.printStackTrace();
}
}
注意:“视图”以类似的方式加载。很好。
FXML文件
<imports...>
<SidePopupView fx:id="sidePopup" side="LEFT" styleclass="mainFxmlClass" xmlns="http://javafx.com/javafx/8.0.40"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="x.y.controller.layoutController">
<StackPane fx:id="stackPane" prefHeight="150.0" prefWidth="200.0">
<children>
<Button />
</children>
</StackPane> <!-- Exception in this line -->
</SidePopupView>
我触发我的图层显示在 HomeViewLoader 类中:
@Override
protected void updateAppBar(AppBar appBar) {
appBar.setNavIcon(MaterialDesignIcon.MENU.button(
e -> MobileApplication.getInstance().showLayer("LAYER"))
);
}
当我尝试在LayerLoader中加载fxml时发生异常。它指的是我的FXML。
它表示StackPane没有定义默认属性。 (javafx.fxml.LoadException:元素未定义默认属性。)
谢谢