- JavaFX Tutorial
- JavaFX - Home
- JavaFX - Overview
- JavaFX Installation and Architecture
- JavaFX - Installation Using Netbeans
- JavaFX - Installation Using Eclipse
- JavaFX - Installation using Visual Studio Code
- JavaFX - Architecture
- JavaFX - Application
- JavaFX 2D Shapes
- JavaFX - 2D Shapes
- JavaFX - Drawing a Line
- JavaFX - Drawing a Rectangle
- JavaFX - Drawing a Rounded Rectangle
- JavaFX - Drawing a Circle
- JavaFX - Drawing an Ellipse
- JavaFX - Drawing a Polygon
- JavaFX - Drawing a Polyline
- JavaFX - Drawing a Cubic Curve
- JavaFX - Drawing a Quad Curve
- JavaFX - Drawing an Arc
- JavaFX - Drawing an SVGPath
- JavaFX Properties of 2D Objects
- JavaFX - Stroke Type Property
- JavaFX - Stroke Width Property
- JavaFX - Stroke Fill Property
- JavaFX - Stroke Property
- JavaFX - Stroke Line Join Property
- JavaFX - Stroke Miter Limit Property
- JavaFX - Stroke Line Cap Property
- JavaFX - Smooth Property
- Operations on 2D Objects
- JavaFX - 2D Shapes Operations
- JavaFX - Union Operation
- JavaFX - Intersection Operation
- JavaFX - Subtraction Operation
- JavaFX Color and Texture
- JavaFX - Colors
- JavaFX Text
- JavaFX - Text
- JavaFX Effects
- JavaFX - Effects
- JavaFX Transformations
- JavaFX - Transformations
- JavaFX Animations
- JavaFX - Animations
- JavaFX Images
- JavaFX - Images
- JavaFX 3D Shapes
- JavaFX - 3D Shapes
- JavaFX - Creating a Box
- JavaFX - Creating a Cylinder
- JavaFX - Creating a Sphere
- Properties of 3D Objects
- JavaFX - Cull Face Property
- JavaFX - Drawing Modes Property
- JavaFX - Material Property
- JavaFX Event Handling
- JavaFX - Event Handling
- JavaFX - Using Convenience Methods
- JavaFX - Event Filters
- JavaFX - Event Handlers
- JavaFX UI Controls
- JavaFX - UI Controls
- JavaFX - ListView
- JavaFX - Accordion
- JavaFX - ButtonBar
- JavaFX - ChoiceBox
- JavaFX - HTMLEditor
- JavaFX - MenuBar
- JavaFX - Pagination
- JavaFX - ProgressIndicator
- JavaFX - ScrollPane
- JavaFX - Separator
- JavaFX - Slider
- JavaFX - Spinner
- JavaFX - SplitPane
- JavaFX - TableView
- JavaFX - TabPane
- JavaFX - ToolBar
- JavaFX - TreeView
- JavaFX - Label
- JavaFX - CheckBox
- JavaFX - RadioButton
- JavaFX - TextField
- JavaFX - PasswordField
- JavaFX - FileChooser
- JavaFX - Hyperlink
- JavaFX - Tooltip
- JavaFX - Alert
- JavaFX - DatePicker
- JavaFX - TextArea
- JavaFX Charts
- JavaFX - Charts
- JavaFX - Creating Pie Chart
- JavaFX - Creating Line Chart
- JavaFX - Creating Area Chart
- JavaFX - Creating Bar Chart
- JavaFX - Creating Bubble Chart
- JavaFX - Creating Scatter Chart
- JavaFX - Creating Stacked Area Chart
- JavaFX - Creating Stacked Bar Chart
- JavaFX Layout Panes
- JavaFX - Layout Panes
- JavaFX - HBox Layout
- JavaFX - VBox Layout
- JavaFX - BorderPane Layout
- JavaFX - StackPane Layout
- JavaFX - TextFlow Layout
- JavaFX - AnchorPane Layout
- JavaFX - TilePane Layout
- JavaFX - GridPane Layout
- JavaFX - FlowPane Layout
- JavaFX CSS
- JavaFX - CSS
- Media with JavaFX
- JavaFX - Playing Video
- JavaFX Useful Resources
- JavaFX - Quick Guide
- JavaFX - Useful Resources
- JavaFX - Discussion
JavaFX - BorderPane Layout
BorderPane Layout in JavaFX
The BorderPane is a layout control that arranges all the UI components of a JavaFX application into five distinc regions namely Top, Left, Right, Bottom and Center positions. The BorderPane layout pane is represented by a class named BorderPane of the javafx.scene.layout package. Instantiating this class will create a BorderPane layout. Constructors of this class are as follows −
BorderPane() − It is the default constructor that creates an empty BorderPane.
BorderPane(Node centerNode) − It constructs a new BorderPane layout and positions the node in the center.
BorderPane(Node center, Node top, Node right, Node bottom, Node left) − This parameterized constructor of BorderPane class used to create a new BorderPane layout with the specified nodes.
The BorderPane class contains five properties, which include −
bottom − This property is of Node type and it represents the node placed at the bottom of the BorderPane. You can set value to this property using the setter method setBottom().
center − This property is of Node type and it represents the node placed at the center of the BorderPane. You can set value to this property using the setter method setCenter().
left − This property is of Node type and it represents the node placed at the left of the BorderPane. You can set value to this property using the setter method setLeft().
right − This property is of Node type and it represents the node placed at the right of the BorderPane. You can set value to this property using the setter method setRight().
top − This property is of Node type and it represents the node placed at the top of the BorderPane. You can set value to this property using the setter method setTop().
The figure below shows how JavaFX nodes are arranged in a BorderPane layout −
In addition to the above mentioned properties and constructors, the BorderPane class also provides the following method −
setAlignment() − This method is used to set the alignment of the nodes belonging to this pane. This method accepts a node and a priority value.
Example
The following program is an example of the BorderPane layout. In this, we are inserting a five text fields in the Top, Bottom, Right, Left and Center positions. Save this code in a file with the name BorderPaneExample.java.
import javafx.application.Application; import javafx.collections.ObservableList; import javafx.scene.Scene; import javafx.scene.control.TextField; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; public class BorderPaneExample extends Application { @Override public void start(Stage stage) { //Instantiating the BorderPane class BorderPane bPane = new BorderPane(); //Setting the top, bottom, center, right and left nodes to the pane bPane.setTop(new TextField("Top")); bPane.setBottom(new TextField("Bottom")); bPane.setLeft(new TextField("Left")); bPane.setRight(new TextField("Right")); bPane.setCenter(new TextField("Center")); //Creating a scene object Scene scene = new Scene(bPane, 400, 300); //Setting title to the Stage stage.setTitle("BorderPane in JavaFX"); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]) { launch(args); } }
Compile and execute the saved java file from the command prompt using the following commands.
javac --module-path %PATH_TO_FX% --add-modules javafx.controls BorderPaneExample.java java --module-path %PATH_TO_FX% --add-modules javafx.controls BorderPaneExample
Output
On executing, the above program generates a JavaFX window as shown below.