I have 3 HBox's set inside a vbox and it displays perfectly centered, up until i try to fit the vbox inside the borderPane. Im trying to have a menu going across the top of the scene and have the rest of my labels and text fields in the center, except my vbox gets pushed to the upper right corner when its put into the border pane. Heres my code, thank you in advance.
//COURSE TITLE PANE
HBox courseTitlePane = new HBox(30);
courseTitlePane.getChildren().addAll(courseTitleLabel,courseTitleField);
courseTitlePane.setAlignment(Pos.CENTER);
//
//COURSE NUMBER PANE
HBox courseNumberPane = new HBox(30);
courseNumberPane.getChildren().addAll(courseNumberLabel,courseNumberField);
courseNumberPane.setAlignment(Pos.CENTER);
//
//COURSE CREDITS PANE
HBox creditsPane = new HBox(30);
creditsPane.getChildren().addAll(numOfCreditsLabel,numOfCreditsField);
creditsPane.setAlignment(Pos.CENTER);
//
//COURSE DESCRIPTION PANE
HBox descriptionPane = new HBox(30);
descriptionPane.getChildren().addAll(courseDescriptionLabel,courseDescriptionField);
descriptionPane.setAlignment(Pos.CENTER);
//
VBox pane = new VBox(30);
pane.getChildren().addAll(courseTitlePane,courseNumberPane,creditsPane,descriptionPane);
pane.setAlignment(Pos.CENTER);
BorderPane root = new BorderPane();
root.getChildren().addAll(pane);
root.setTop(menuBar);
Scene scene = new Scene(root,800,500);
primaryStage.setScene(scene);
primaryStage.show();
@James_D comment is indeed correct. If you look at the BorderPane documentation it describes that a BorderPane "lays out children in top, left, right, bottom, and center positions."
So just like you set your menuBar to be added to the top of the BorderPane with
root.setTop(menuBar);
, to set the center content of the BorderPane you must useroot.setCenter(pane);
.Here is a full example: