package com.example; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.BorderPane; import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.stage.Stage; public class BorderPaneExample extends Application { BorderPane borderPane = new BorderPane(); // Container for the app // Setup UI elements here Label topLbl = new Label("Top"); Label leftLbl = new Label("Left"); Label rightLbl = new Label("Right"); Label bottomLbl = new Label("Bottom"); Button centerBtn = new Button("Center"); // Using a VBox (Veritcal Box) to hold UI elements VBox topVb = new VBox(); VBox leftVb = new VBox(); VBox rightVb = new VBox(); VBox bottomVb = new VBox(); @Override public void init(){ // Use the init method to configure widgets // Set fonts for all labels using CSS topLbl.setFont(Font.font("Verdana", FontWeight.BOLD, 18)); leftLbl.setFont(Font.font("Verdana", FontWeight.BOLD, 18)); rightLbl.setFont(Font.font("Verdana", FontWeight.BOLD, 18)); bottomLbl.setFont(Font.font("Verdana", FontWeight.BOLD, 18)); // Configure the VBoxes topVb.getChildren().add(topLbl); topVb.setAlignment(Pos.CENTER); topVb.setStyle("-fx-border-stylel:solid; -fx-border-width:1pt; -fx-border-color:black;"); leftVb.getChildren().add(leftLbl); leftVb.setAlignment(Pos.CENTER); leftVb.setStyle("-fx-border-stylel:solid; -fx-border-width:1pt; -fx-border-color:black;"); rightVb.getChildren().add(rightLbl); rightVb.setAlignment(Pos.CENTER); rightVb.setStyle("-fx-border-stylel:solid; -fx-border-width:1pt; -fx-border-color:black;"); bottomVb.getChildren().add(bottomLbl); bottomVb.setAlignment(Pos.CENTER); bottomVb.setStyle("-fx-border-stylel:solid; -fx-border-width:1pt; -fx-border-color:black;"); // Add VBoxes to Pane borderPane.setTop(topVb); borderPane.setLeft(leftVb); borderPane.setRight(rightVb); borderPane.setBottom(bottomVb); borderPane.setCenter(centerBtn); // Button event handler centerBtn.setOnAction(new EventHandler() { @Override public void handle(ActionEvent event) { System.out.println("Center clicked!"); } }); } public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Border Pane Example"); primaryStage.setScene(new Scene(borderPane, 300, 250)); primaryStage.show(); } }