我想为我的客户创建一个 JavaFX 应用程序。我找到了 DataFX 框架并喜欢它。但是我有问题,@FXMLViewFlowContext
因为null
每次我从父母那里调用 child fview 时它都会返回。我使用了 lib 版本 8.0.7 及以下代码
我使用 i18n 资源在主控制器中创建侧视图:
// side controller will add links to the content flow Flow sideMenuFlow = new Flow(SideMenuController.class); sideMenuFlowHandler = new FlowHandler(sideMenuFlow, context, Common.getViewConfiguration()); drawer.setSidePane(sideMenuFlowHandler.start(new AnimatedFlowContainer(Duration.millis(320), ContainerAnimations.SWIPE_LEFT)));
这是我的侧窗格控制器
@FXMLController(value = "/res/fxml/test.fxml") public class SideMenuController { @FXMLViewFlowContext private ViewFlowContext context; @FXML private JFXListView test; @FXML @ActionTrigger("suppliers") private JFXButton suppliers; @FXML @ActionTrigger("history") private JFXButton history; @FXML @ActionTrigger("barcode") private JFXButton barcode; @FXML @ActionTrigger("settings") private JFXButton settings; @FXML @ActionTrigger("report") private JFXButton report; @FXML @ActionTrigger("users") private JFXButton users; @FXML @ActionTrigger("inventory") private JFXButton inventory; @FXML @ActionTrigger("shops") private JFXButton shops; @FXML @ActionTrigger("calculation") private JFXButton calculation; @PostConstruct public void initialize(){ test.propagateMouseEventsToParent(); System.out.println(context); FlowHandler contentFlowHandler = (FlowHandler) context.getRegisteredObject("ContentFlowHandler"); Flow contentFlow = (Flow) context.getRegisteredObject("ContentFlow"); bindNodeToController(suppliers, SuppliersController.class, contentFlow, contentFlowHandler); bindNodeToController(inventory, InventoryController.class, contentFlow, contentFlowHandler); bindNodeToController(users, UsersController.class, contentFlow, contentFlowHandler); bindNodeToController(history, HistoryController.class, contentFlow, contentFlowHandler); bindNodeToController(shops, ShopsController.class, contentFlow, contentFlowHandler); bindNodeToController(report, ReportController.class, contentFlow, contentFlowHandler); bindNodeToController(barcode, BarcodeController.class, contentFlow, contentFlowHandler); bindNodeToController(calculation, CalculationController.class, contentFlow, contentFlowHandler); bindNodeToController(settings, SettingsController.class, contentFlow, contentFlowHandler); } private void bindNodeToController(Node node, Class<?> controllerClass, Flow flow, FlowHandler flowHandler) { flow.withGlobalLink(node.getId(), controllerClass); node.setOnMouseClicked((e) -> { try { flowHandler.handle(node.getId()); } catch (Exception e1) { e1.printStackTrace(); } }); } }
当我运行我的程序时,我得到一个NullPointerException
因为上下文从未被注入。我搜索但没有找到任何解决方案。我也尝试过旧图书馆,但没有帮助。