Question

I have a JavaFX application that displays a Scene with a single immediate child -- an AnchorPane loaded from FXML file.

@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();
}

It has a child Pane with an fx:id that I reference in the controller class via the @FXML annotation, as well as a button similarly hooked up to an @FXML method. When I click the button, the method attempts to load a different FXML file and replace the children of the pane with the newly-loaded 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();
    }
}

That part seems to happen correctly -- the child FXML contents are displayed on the screen -- but at that point no further UI input occurs. Tooltips on the button don't display and it is not clickable. However, no exception is thrown.

Était-ce utile?

La solution

Some further experimentation revealed the problem -- the child node added to the contentPane was bigger than the parent -- which appears to mean it intercepts the click events for the buttons which are now underneath it.

There's probably a better pattern for adding these types of child nodes to a frame, but at least my current issue has been explained -- the UI isn't locked up at all!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top