JavaFX | BorderPane Class

01 Sep, 2021
BorderPane class is a part of JavaFX. BorderPane class lays its children in top, bottom, center, left and, right positions. BorderPane lays out each child set in the five positions regardless of the child’s visible property value unmanaged children are ignored. BorderPane class inherits Pane class. Constructor of the class: 
BorderPane(): Creates a new Border Pane.BorderPane(Node c): Creates a new Border Pane with specified node at center.BorderPane(Node center, Node top, Node right, Node bottom, Node left): Creates an BorderPane layout with the given Nodes to use for each of the main layout areas of the Border Pane.
BorderPane(): Creates a new Border Pane.
BorderPane(Node c): Creates a new Border Pane with specified node at center.
BorderPane(Node center, Node top, Node right, Node bottom, Node left): Creates an BorderPane layout with the given Nodes to use for each of the main layout areas of the Border Pane.
Commonly Used Methods: 
Below programs illustrate the use of BorderPane Class:  
Java Program to create a BorderPane and add it to the stage: In this program we create a Label named label. Now create a BorderPane named borderpane. We will add this label to the BorderPane layout in its center. Add the border pane to the scene and add this scene to the stage and display the stage to show the final results. 
Java Program to create a BorderPane and add it to the stage: In this program we create a Label named label. Now create a BorderPane named borderpane. We will add this label to the BorderPane layout in its center. Add the border pane to the scene and add this scene to the stage and display the stage to show the final results. 
Java
// Java Program to create a BorderPane// and add it to the stageimport javafx.application.Application;import javafx.scene.Scene;import javafx.scene.control.*;import javafx.scene.layout.*;import javafx.stage.Stage;import javafx.event.ActionEvent;import javafx.event.EventHandler;import javafx.scene.canvas.*;import javafx.scene.web.*;import javafx.scene.layout.BorderPane;import javafx.scene.shape.*; public class BorderPane_1 extends Application {     // launch the application    public void start(Stage stage)    {         try {             // set title for the stage            stage.setTitle("BorderPane");             // create a label            Label label = new Label("this is BorderPane example");             // create a BorderPane            BorderPane border_pane = new BorderPane(label);             // create a scene            Scene scene = new Scene(border_pane, 400, 300);             // set the scene            stage.setScene(scene);             stage.show();        }         catch (Exception e) {             System.out.println(e.getMessage());        }    }     // Main Method    public static void main(String args[])    {         // launch the application        launch(args);    }}
Output: 
Java Program to create a BorderPane and add Center, top, bottom, left, right components and add it to the stage: In this program we create Labels named label_center, label_top, label_bottom, label_right, label_left. Now create a BorderPane named borderpane. We will add this label to the BorderPane layout in its center, top, bottom, right, left. Set the alignments of the labels to center by using setAlignment(). We will add border pane to the scene and add this scene to the stage and display the stage to show the final results. 
Java Program to create a BorderPane and add Center, top, bottom, left, right components and add it to the stage: In this program we create Labels named label_center, label_top, label_bottom, label_right, label_left. Now create a BorderPane named borderpane. We will add this label to the BorderPane layout in its center, top, bottom, right, left. Set the alignments of the labels to center by using setAlignment(). We will add border pane to the scene and add this scene to the stage and display the stage to show the final results. 
Java
// Java Program to create a BorderPane and// add Center, top, bottom, left, right// components and add it to the stageimport javafx.application.Application;import javafx.scene.Scene;import javafx.scene.control.*;import javafx.scene.layout.*;import javafx.stage.Stage;import javafx.event.ActionEvent;import javafx.event.EventHandler;import javafx.scene.canvas.*;import javafx.scene.web.*;import javafx.scene.layout.BorderPane;import javafx.scene.shape.*;import javafx.geometry.*; public class BorderPane_2 extends Application {     // launch the application    public void start(Stage stage)    {         try {             // set title for the stage            stage.setTitle("BorderPane");             // create a label            Label label_center = new Label("this is BorderPane center");            Label label_top = new Label("this is BorderPane top");            Label label_bottom = new Label("this is BorderPane bottom");            Label label_left = new Label("this is BorderPane left");            Label label_right = new Label("this is BorderPane right");             // create a BorderPane            BorderPane border_pane = new BorderPane(label_center,               label_top, label_right, label_bottom, label_left);             // set alignment            border_pane.setAlignment(label_top, Pos.CENTER);            border_pane.setAlignment(label_bottom, Pos.CENTER);            border_pane.setAlignment(label_left, Pos.CENTER);            border_pane.setAlignment(label_right, Pos.CENTER);             // create a scene            Scene scene = new Scene(border_pane, 400, 300);             // set the scene            stage.setScene(scene);             stage.show();        }         catch (Exception e) {             System.out.println(e.getMessage());        }    }     // Main Method    public static void main(String args[])    {         // launch the application        launch(args);    }}
Output: 
Note: The above programs might not run in an online IDE please use an offline compiler.Reference: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/layout/BorderPane.html 
kalrap615
JavaFX
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Object Oriented Programming (OOPs) Concept in Java
How to iterate any Map in Java
HashMap in Java with Examples
Stream In Java
ArrayList in Java
Collections in Java
Singleton Class in Java
Multidimensional Arrays in Java
Set in Java
Stack Class in Java