How do I switch between layouts in Javax?

61 Views Asked by At

I am designing a javaFX application. I am struggling with switching between BorderPanes. I have desgined two pages(FXML files) the first one is the home page which consists of some containers like (VBox, BorderPane, etc..). And the second one consists of only a BorderPane. How do I switch between the BorderPane of the first page to the BorderPane of the second page?

here is the Main class code

 package main;

import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class  MainMethod extends Application{

private Stage primaryStage;
private VBox MainLayout;
private AnchorPane submain;


    @Override
    public void start(Stage primaryStage) throws IOException{
        this.primaryStage = primaryStage;
        this.primaryStage.setTitle("Nursery");
        showMainView();
         showMainPane();
    }
    
    private void showMainView() throws IOException{
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(MainMethod.class.getResource("../controller/Add_child.fxml"));
        MainLayout = loader.load();
        Scene secne = new Scene(MainLayout);
        primaryStage.setScene(secne);
        primaryStage.show();
    }
    
    private void showMainPane() throws IOException{
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(MainMethod.class.getResource("../controller/Add_ChildPane.fxml"));
        VBox mainitems = loader.load(); // I am Struggling here I think
        
            
    }
    
    public static void main (String[] args){
        System.out.println("sfdf");
        launch(args);
    }
}
0

There are 0 best solutions below