JavaFX | BorderPane Class
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.
Commonly Used Methods:
| Methods | Explanaion |
|---|---|
| getAlignment(Node c) | Returns the alignment of the node. |
| getBottom() | Returns the bottom node of the border pane. |
| getCenter() | Returns the center node of the border pane. |
| getLeft() | Returns the left node of the border pane. |
| getRight() | Returns the right node of the border pane. |
| getTop() | Returns the top node of the border pane. |
| setAlignment(Node c, Pos v) | Sets the alignment of node c to pos v. |
| setBottom(Node v) | Sets the bottom node of the border pane. |
| setCenter(Node v) | Sets the center node of the border pane. |
| setLeft(Node v) | Sets the left node of the border pane. |
| setRight(Node v) | Sets the right node of the border pane. |
| setTop(Node v) | Sets the top node of the border pane. |
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 stageimportjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.control.*;importjavafx.scene.layout.*;importjavafx.stage.Stage;importjavafx.event.ActionEvent;importjavafx.event.EventHandler;importjavafx.scene.canvas.*;importjavafx.scene.web.*;importjavafx.scene.layout.BorderPane;importjavafx.scene.shape.*;publicclassBorderPane_1extendsApplication {// launch the applicationpublicvoidstart(Stage stage){try{// set title for the stagestage.setTitle("BorderPane");// create a labelLabel label =newLabel("this is BorderPane example");// create a BorderPaneBorderPane border_pane =newBorderPane(label);// create a sceneScene scene =newScene(border_pane,400,300);// set the scenestage.setScene(scene);stage.show();}catch(Exception e) {System.out.println(e.getMessage());}}// Main Methodpublicstaticvoidmain(String args[]){// launch the applicationlaunch(args);}}chevron_rightfilter_noneOutput:

- 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 stageimportjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.control.*;importjavafx.scene.layout.*;importjavafx.stage.Stage;importjavafx.event.ActionEvent;importjavafx.event.EventHandler;importjavafx.scene.canvas.*;importjavafx.scene.web.*;importjavafx.scene.layout.BorderPane;importjavafx.scene.shape.*;importjavafx.geometry.*;publicclassBorderPane_2extendsApplication {// launch the applicationpublicvoidstart(Stage stage){try{// set title for the stagestage.setTitle("BorderPane");// create a labelLabel label_center =newLabel("this is BorderPane center");Label label_top =newLabel("this is BorderPane top");Label label_bottom =newLabel("this is BorderPane bottom");Label label_left =newLabel("this is BorderPane left");Label label_right =newLabel("this is BorderPane right");// create a BorderPaneBorderPane border_pane =newBorderPane(label_center,label_top, label_right, label_bottom, label_left);// set alignmentborder_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 sceneScene scene =newScene(border_pane,400,300);// set the scenestage.setScene(scene);stage.show();}catch(Exception e) {System.out.println(e.getMessage());}}// Main Methodpublicstaticvoidmain(String args[]){// launch the applicationlaunch(args);}}chevron_rightfilter_noneOutput:

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
Recommended Posts:
- JavaFX | Tab Class
- JavaFX | Pos Class
- JavaFX | InnerShadow Class
- JavaFX | ColorInput Class
- JavaFX | HTMLEditor Class
- JavaFX | ColorAdjust Class
- JavaFX | SepiaTone Class
- JavaFX | Rectangle2D Class
- JavaFX | SplitPane Class
- JavaFX | TitledPane Class
- JavaFX | Duration Class
- JavaFX | ToggleButton Class
- JavaFX | Popup Class
- JavaFX | Point2D Class
- JavaFX | Dimension2D Class
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



