繁体   English   中英

将子级添加到窗格后,JavaFX应用程序停止响应

[英]JavaFX app stops responding after adding child to Pane

我有一个JavaFX应用程序,它显示一个带有单个直属子级的Scene -从FXML文件加载的AnchorPane

@Override
public void start(Stage primaryStage) throws Exception {
    this.primaryStage = primaryStage;
    this.injector = Guice.createInjector(new UiModule(), new CommonModule());

    final EventBus eventBus = injector.getInstance(EventBus.class);
    eventBus.register(this);

    final FXMLLoader loader = injector.getInstance(FXMLLoader.class);
    final Parent root = loader.load(SphinxApp.class
        .getResourceAsStream("/com/atomiccomics/sphinx/ui/survey/SurveyFrame.fxml"));

    final Scene scene = new Scene(root);

    primaryStage.setScene(scene);
    primaryStage.show();
}

它有一个带有fx:id的子Pane ,我通过@FXML批注在控制器类中进行了引用,还有一个类似地与@FXML方法挂钩的按钮。 当我单击按钮时,该方法尝试加载另一个FXML文件,并用新加载的Node替换窗格的子级。

@FXML
private Pane contentPane;

//Further down...

@FXML
public void next() {
    final FXMLLoader loader = loaderProvider.get();
    try {
        final Node panel = loader.load(SurveyController.class.getResourceAsStream("Instructions.fxml"));
        contentPane.getChildren().clear();
        contentPane.getChildren().add(panel);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

该部分似乎正确发生了-子FXML内容显示在屏幕上-但此时没有进一步的UI输入发生。 该按钮上的工具提示不会显示,并且无法单击。 但是,不会引发异常。

一些进一步的实验揭示了问题-添加到子节点contentPane比父母更大的 -这似乎意味着它拦截了现在是在它下面的按钮点击事件。

将这些类型的子节点添加到框架中可能是更好的模式,但是至少已经解释了我当前的问题-UI根本没有锁定!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM