#GridPane contents moving when swapping fxml files.

3 messages · Page 1 of 1 (latest)

rancid mortar
#

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?

fringe birchBOT
#

This post has been reserved for your question.

Hey @rancid mortar! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.