konstantin konstantin - 2 months ago 13
Java Question

Structure items in a javafx interface

I am trying to figure out how exactly the javafx item structure works. I have the following interface:

enter image description here

This interface is created in javafx and its a Scene sceneChooseUser

StackPane layoutChooseUser = new MyLayout();
Scene sceneChooseUser = new Scene(layoutChooseUser, 1100, 750);
layoutChooseUser.getChildren().add(border);


My code for the border:

learnin = new MyTitles("Learnin'");
learnin.setStyle("-fx-font: 140 impact; -fx-text-fill: white;");
chooseUserPane.add(learnin, 1, 1);
chooseUserButtonPane = new GridPane();
chooseUserButtonPane.setHgap(100);
chooseUserButtonPane.setPadding(new Insets(0, 20, 0, 80));
teacherButton = new Button("TEACHER ACCOUNT");
teacherButton.setOnAction(e -> primaryStage.setScene(sceneTLogIn));
teacherButton.setPrefWidth(320.0);
teacherButton.setPrefHeight(320.0);
teacherButton.setStyle("-fx-font: 45 cornerstone; -fx-base: #17499F;");
teacherButton.setWrapText(true);
chooseUserButtonPane.add(teacherButton, 1, 16);
studentButton = new Button("STUDENT ACCOUNT");
studentButton.setOnAction(e -> primaryStage.setScene(sceneSLogIn));
studentButton.setPrefWidth(320.0);
studentButton.setPrefHeight(320.0);
studentButton.setStyle("-fx-font: 45 cornerstone; -fx-base: #17499F;");
studentButton.setWrapText(true);
chooseUserButtonPane.add(studentButton, 2, 16);
BorderPane border = new BorderPane();
border.setTop(chooseUserPane);
border.setCenter(chooseUserButtonPane);


I am trying to structure the whole scene and give some space between my label and the two buttons. How can I achieve that?

Answer

Using the layout you have, you can do

BorderPane.setMargin(chooseUserPane, new Insets(0, 0, 20, 0));

to add 20 pixels margin below the label.