The BorderPane layout can be used to add 5 nodes. Here the nodes are different colored rectangles.
Usually, the nodes, will be other layouts such as VBox, HBox, or GridPane.
package ex20;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class Ex20 extends Application {
@Override
public void start(Stage primaryStage) {
Rectangle rectTop = new Rectangle(400, 100, Color.RED);
Rectangle rectBottom = new Rectangle(400, 100, Color.GREEN);
Rectangle rectLeft = new Rectangle(100, 200, Color.BLUE);
Rectangle rectRight = new Rectangle(100, 200, Color.CYAN);
Rectangle rectCenter = new Rectangle(200, 200, Color.YELLOW);
BorderPane borderPane = new BorderPane();
borderPane.setTop(rectTop);
borderPane.setBottom(rectBottom);
borderPane.setCenter(rectCenter);
borderPane.setRight(rectRight);
borderPane.setLeft(rectLeft);
Scene scene = new Scene(borderPane, 400, 400);
primaryStage.setTitle("Example 20. BorderPane");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
This is the output:
No comments:
Post a Comment