JavaFX: BorderPane class

This entry is part 9 of 55 in the series JavaFX

BorderPane lays out children in the scene in top, left, right, bottom, and center positions similar to the illustration in the screenshot below.



There are a few panes commonly used in JavaFX in laying out the boxes in the scene.  In the screenshot above, we have the Top pane and to place items in the Top pane, we can use the HBox pane class.

Consider the example below, the addHorizontalBox method basically set up the 2 buttons for display in the top panel.

package javafxapplication9;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class JavaFXApplication9 extends Application {
    public void start(Stage stage) {
        BorderPane border = new BorderPane();
        HBox hbox = addHorizontalBox();

        Scene scene = new Scene(border);
        stage.setTitle("Layout Sample");;
    private HBox addHorizontalBox() {

        HBox hbox = new HBox();
        hbox.setPadding(new Insets(15, 12, 15, 12));
        hbox.setSpacing(10);   // Gap between nodes
        hbox.setStyle("-fx-background-color: blue;");

        Button buttonAccept = new Button("Accept");
        buttonAccept.setPrefSize(100, 20);

        Button buttonNext = new Button("Next");
        buttonNext.setPrefSize(100, 20);
        hbox.getChildren().addAll(buttonAccept, buttonNext);
        return hbox;
    public static void main(String[] args) {


Series Navigation<< JavaFX: Setting Constraints On Children
JavaFX: BorderPane and VBox >>