×

JavaFX BorderPane

In the JavaFX application, in order to set Border Pane as a layout, the BorderPane class is used. The BorderPane layout allows us to arrange the components in the left, right, top, bottom, and center of the container. All methods needed for this purpose are present in the javafx.scene.layout.BorderPane class.

Properties and corresponding methods to set BorderPane as a layout:

1. Top

This property of the Border Pane class allows us to define the position of the component at the top of the container and the setTop() method helps to set it.

2. Bottom

This property of the Border Pane class allows us to define the position of the component at the bottom of the container and the setBottom() method helps to set it.

3. Left

This property of the Border Pane class allows us to define the position of the component at the left of the container and the setLeft() method helps to set it.

4. Right

This property of the Border Pane class allows us to define the position of the component at the right of the container and the setRight() method helps to set it.

5. Center

This property of the Border Pane class allows us to define the position of the component at the center of the container and the setCenter() method helps to set it.

Layouts in JavaFX applications- Simple BorderPane

Example:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;






public class BorderUI extends Application 
{  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
      
    Label label = new Label(" Simple BorderPane example ");
     
        BorderPane box = new BorderPane(label);
         Scene scene = new Scene(box,600,400);  
         
           primaryStage.setScene(scene);  
           primaryStage.setTitle(" JavaFX Layout - Simple BorderPane layout");  
           primaryStage.show();  
        }


    public static void main(String[] args) 
  {
        Application.launch(args);
    }
}

Output:

In order to create the Border Pane in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.stage.Stage, javafx.scene.Scene, javafx.scene.control.Label, javafx.scene.layout.BorderPane.

Then we have created one class named BorderUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold Border Pane with the label, a Border Pane object is created which is then passed to the Scene class object.

Border Pane is created with the help of its constructor and the component is passed in it.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is invoked. In output Frame like container is displayed with the title, " JavaFX Layout - Simple BorderPane layout”. Also, it displays Border Pane with the label of Simple BorderPane example placed in the center.

Layouts in JavaFX applications- BorderPane

Layouts in JavaFX applications- BorderPane with components at Top, Bottom, Left, Right, and Center

Example:

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;


public class BorderUI extends Application
 {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
      
      Label new_center = new Label("BorderPane center");
      Label new_top = new Label("BorderPane top");
      Label new_bottom = new Label(" BorderPane bottom");
      Label new_left = new Label(" BorderPane left");
      Label new_right = new Label(" BorderPane right");
              BorderPane pane = new BorderPane(new_center,
             new_top, new_right, new_bottom, new_left);
          pane.setAlignment(new_top, Pos.CENTER);
         pane.setAlignment(new_bottom, Pos.CENTER);
          pane.setAlignment(new_left, Pos.CENTER);
          pane.setAlignment(new_right, Pos.CENTER);
         Scene scene = new Scene(pane,600,400);  
         
           primaryStage.setScene(scene);  
           primaryStage.setTitle(" JavaFX Layout -  BorderPane layout Example");  
           primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the Border Pane with the components in all the directions in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.stage.Stage, javafx.scene.Scene, javafx.scene.control.Label, javafx.scene.layout.BorderPane, javafx.geometry.Pos.

Then we have created one class named BorderUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold Border Pane with components in all directions, a Border Pane object is created which is then passed to the Scene class object.

Border Pane is created with the help of its constructor and component in the left, right, center, top, and bottom of the container.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is invoked. In output Frame like container is displayed with the title, " JavaFX Layout -  BorderPane layout Example ”. Also, it displays Border Pane with 5 labels at the top, bottom, left, right, and center of the container.

Layouts in JavaFX applications- BorderPane

Related Topics

JavaFX Arc

In the JavaFX application, in order to draw an arc, the Arc class is used. The Arc allows us to join any points in the space. All methods needed for...

5 minutes read.

JavaFX Selectors

In the JavaFX application, in order to apply various css effect, we use the various css classes available in the JavaFX. This is generally used to enhance the appearance property...

4 minutes read.

JavaFX Convenience Methods

The JavaFX allows us to use various convenience methods to handle events on various nodes in JavaFX applications. The convenience methods provides us easy and effective way to add any...

4 minutes read.

JavaFX Label

The UI Control Label in a JavaFX is used to display the simple text. To use Label in JavaFX application javafx.scene.control.The label class is used. We can place Labels on...

3 minutes read.

JavaFX Shear

In the JavaFX application, in order to apply various shear effect, we use this class. It has the ability to shear the given object along the x or y axis....

3 minutes read.

JavaFX Circle

In the JavaFX application, in order to draw a circle, the Circle class is used. The Circle allows us to join any points in the space. All methods needed for...

4 minutes read.

JavaFX PasswordField

In the JavaFX application, to get the user information and password as input from the user, a form is created using textfields and password fields which allows the user to...

4 minutes read.

JavaFX HBox

In the JavaFX application, in order to set HBox as a layout, the HBox class is used. The HBox layout allows us to arrange the components in one row. All...

3 minutes read.

JavaFX GridPane

In the JavaFX application, in order to set Grid Pane as a layout, the GridPane class is used. The GridPane layout allows us to arrange the components in the form...

4 minutes read.

JavaFX Lighting

In the JavaFX application, in order to apply various Lighting effect from a single source, we use this class. It has the ability to lighten a node from a given...

4 minutes read.

JavaFX Rotate Transition

In the JavaFX application, in order to generate the rotate transition, we have to apply rotation transition on any particular shape. It has the ability to rotate the shape along...

4 minutes read.

JavaFX Installation

In order to run JavaFX applications, we need to have eclipse and java installed on our machine. Prerequisite: Operating systemAny Operating system (Windows, Linux, Mac)Memory requirementNo minimum requirementDisk SpaceNo minimum requirementJDK versionJDK...

3 minutes read.

JavaFX TilePane

In the JavaFX application, in order to set TilePane as a layout, the TilePane class is used. The TilePane layout allows us to arrange the components in the same sized...

4 minutes read.

JavaFX Image Input

In the JavaFX application, in order to apply various image input effect, we use the ImageInput class. It has the ability to fill the specified shape with a given image...

4 minutes read.

JavaFX Color Adjust

In the JavaFX application, in order to apply various color adjust effect, we use ColorAdjust class. It has the ability to apply various color adjust effect such as hue, saturation,...

5 minutes read.

JavaFX - Basic Structure of Application

Every JavaFX application is mainly divided into three main components namely Scene, Stage, and nodes. For using these components we need to import javafx.application.Application class in every javafx application. Life...

4 minutes read.

JavaFX StackPane

In the JavaFX application, in order to set Stack Pane as a layout, the StackPane class is used. The StackPane layout allows us to arrange the components in the stack...

4 minutes read.

JavaFX Menu

In the JavaFX application, in order to create a menu, menu items, and menu bar, Menu, MenuItem, and MenuBar class is used. The menu allows us to choose options among...

4 minutes read.

JavaFX Gaussian Blur

In the JavaFX application, in order to apply various Gaussian blur effect, we use GaussianBlur class. It has the ability to apply blur effect on the given object. All methods...

4 minutes read.

JavaFX Bloom

In the JavaFX application, in order to apply various bloom effect, we use the Bloom class. It has the ability to bloom the colors of the shape. All methods needed...

4 minutes read.