Loading new fxml in the same scene

Why your code does not work The loader creates a new AnchorPane, but you never add the new pane to a parent in the scene graph. Quick Fix Instead of: content = (AnchorPane) FXMLLoader.load(“vista2.fxml”); Write: content.getChildren().setAll(FXMLLoader.load(“vista2.fxml”)); Replacing the content children with your new vista. The content itself remains in the scene graph, so when you … Read more

Accessing FXML controller class

You can get the controller from the FXMLLoader FXMLLoader fxmlLoader = new FXMLLoader(); Pane p = fxmlLoader.load(getClass().getResource(“foo.fxml”).openStream()); FooController fooController = (FooController) fxmlLoader.getController(); store it in your main stage and provide getFooController() getter method. From other classes or stages, every time when you need to refresh the loaded “foo.fxml” page, ask it from its controller: getFooController().updatePage(strData); … Read more