Search code examples
javajavafxborderpane

How to change CenterPane from LeftPane in javaFx borderPane?


I am trying to make a panel in javafx and i used to a border pane as a main scene. There are 4 windows (main1, main2, main3,main4) for center panel, and there is a navigation menu in left panel.

borderPane.setCenter(mainMenu1.getCenterMain1UI());
//borderPane.setCenter(mainMenu2.getCenterMain2UI());
//borderPane.setCenter(mainMenu3.getCenterMain3UI());
//borderPane.setCenter(mainMenu4.getCenterMain4UI());


public BorderPane getAppWindow(){

    if (borderPane == null){

        borderPane = new BorderPane();
        borderPane.setTop(topPanel.getTopPanelUI());
        borderPane.setBottom(bottomPanel.getBottomPanelUI());
        borderPane.setLeft(leftPanel.getLeftPanelUI());

        borderPane.setCenter(mainMenu.getCenterMainUI());
        borderPane.setAlignment(borderPane.getCenter(), Pos.TOP_LEFT);

    }

    return borderPane;
}

in the left panel controller

 public class LeftPanelController {

        public VBox leftPanelPane;

        public Button btnLeftPanelMainmenu;
        public Button btnLeftPanelDb;
        public Button btnLeftPanelOfficeInfo;
        public Button btnLeftPanelConfiguration;



        public void btnLeftPanelMainmenuOnClickAction(ActionEvent e){
            change border pane center to main
        }

        public void btnLeftPanelDbOnClickAction(ActionEvent e){
            change border pane center to DB
        }

        public void btnLeftPanelOfficeInfoOnClickAction(ActionEvent e){
            change border pane center to DB
        }

        public void btnLeftPanelConfigurationOnClickAction(ActionEvent e){
            change border pane center to configuration
        }

    }

Solution

  • I changed my button click methods in the left panel like that;

        public void btnLeftPanelMainmenuOnClickAction(ActionEvent e) {
            AppWindow.borderPane.setCenter(AppWindow.mainMenu.getCenterMainUI());
        }
    
        public void btnLeftPanelDbOnClickAction(ActionEvent e) {
            AppWindow.borderPane.setCenter(AppWindow.dbMenu.getCenterDbUI());
        }
    
        public void btnLeftPanelConfigurationOnClickAction(ActionEvent e) {
            AppWindow.borderPane.setCenter(AppWindow.configMenu.getCenterConfigurationUI());
        }