I am working on a JavaFX project and I need to swap to different screens. To do this, I found this method.
@FXMLprivate GridPane rootPane;
private void configureButtonEvents() { swapViewBtn.setOnAction(new EventHandler<>() { @Override public void handle(ActionEvent e) { try { rootPane.getChildren().clear(); FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(MainApplication.class.getResource("customer-view.fxml"))); Parent root = loader.load(); MainCustController mainCustController = loader.getController(); rootPane.getChildren().setAll(root); } catch (IOException ex) { throw new RuntimeException(ex); } } });}
But whenever I press the button to swap screens, it swaps successfully, but the contents shift down and to the left. So as I swap back and forth the screen will eventually be completely hidden outside of the window.
I have no idea why this might be happening and I am new to Javafx so is there something I am missing?