Java Reference
In-Depth Information
The getter and setter methods for property values
and a getter for property itself are provided in the class,
but omitted in the UML diagram for brevity.
javafx.scene.layout.BorderPane
-top: ObjectProperty<Node>
-right: ObjectProperty<Node>
-bottom: ObjectProperty<Node>
-left: ObjectProperty<Node>
-center: ObjectProperty<Node>
The node placed in the top region (default: null ).
The node placed in the right region (default: null ).
The node placed in the bottom region (default: null ).
The node placed in the left region (default: null ).
The node placed in the center region (default: null ).
+BorderPane()
+setAlignment(child: Node, pos:
Pos)
Creates a BorderPane .
Sets the alignment of the node in the BorderPane .
F IGURE 14.20
BorderPane places the nodes in top, bottom, left, right, and center regions.
Listing 14.12 gives a program that demonstrates BorderPane . The program places five
buttons in the five regions of the pane, as shown in FigureĀ 14.21.
L ISTING 14.12
ShowBorderPane.java
1 import javafx.application.Application;
2 import javafx.geometry.Insets;
3 import javafx.scene.Scene;
4 import javafx.scene.control.Label;
5 import javafx.scene.layout.BorderPane;
6 import javafx.scene.layout.StackPane;
7 import javafx.stage.Stage;
8
9 public class ShowBorderPane extends Application {
10 @Override // Override the start method in the Application class
11
public void start(Stage primaryStage) {
12
// Create a border pane
13
BorderPane pane = new BorderPane();
create a border pane
14
15 // Place nodes in the pane
16 pane.setTop( new CustomPane( " Top " ));
17 pane.setRight( new CustomPane( " Right " ));
18 pane.setBottom( new CustomPane( " Bottom " ));
19 pane.setLeft( new CustomPane( " Left " ));
20 pane.setCenter( new CustomPane( " Center " ));
21
22 // Create a scene and place it in the stage
23 Scene scene = new Scene(pane);
24 primaryStage.setTitle( " ShowBorderPane " ); // Set the stage title
25 primaryStage.setScene(scene); // Place the scene in the stage
26 primaryStage.show(); // Display the stage
27 }
28 }
29
30 // Define a custom pane to hold a label in the center of the pane
31 class CustomPane extends StackPane {
32 public CustomPane(String title) {
33 getChildren().add( new Label(title));
34
add to top
add to right
add to bottom
add to left
add to center
define a custom pane
add a label to pane
set style
set padding
setStyle( " -fx-border-color: red " );
35
setPadding( new Insets( 11.5 , 12.5 , 13.5 , 14.5 ));
36 }
37 }
 
 
Search WWH ::




Custom Search