📅  最后修改于: 2023-12-03 15:16:03.244000             🧑  作者: Mango
JavaFX provides various layout panes that enable developers to create user interfaces that can resize and respond appropriately to changes in the window size or to changes in the content.
The BorderPane layout divides the space into five areas: top, right, bottom, left, and center. It is commonly used for laying out a main window or a dialog box.
BorderPane borderPane = new BorderPane();
borderPane.setTop(topNode);
borderPane.setRight(rightNode);
borderPane.setBottom(bottomNode);
borderPane.setLeft(leftNode);
borderPane.setCenter(centerNode);
The VBox layout arranges nodes in a vertical column. It is used when you want to add multiple nodes vertically.
VBox vBox = new VBox();
vBox.getChildren().addAll(node1, node2, node3);
The HBox layout arranges nodes in a horizontal row. It is used when you want to add multiple nodes horizontally.
HBox hBox = new HBox();
hBox.getChildren().addAll(node1, node2, node3);
The FlowPane layout arranges nodes in a flow, from left to right in rows. It is used when you want to create a flexible layout that adapts to changes in the window size.
FlowPane flowPane = new FlowPane();
flowPane.getChildren().addAll(node1, node2, node3);
The GridPane layout is used when you want to create a grid of nodes. It enables you to specify the number of rows and columns and the relative sizes of each row and column, as well as the placement of nodes within the grid.
GridPane gridPane = new GridPane();
gridPane.add(node1, 0, 0);
gridPane.add(node2, 1, 0);
gridPane.add(node3, 0, 1);
The StackPane layout stacks nodes on top of each other. It is used when you want to create an overlay effect by layering nodes on top of each other.
StackPane stackPane = new StackPane();
stackPane.getChildren().addAll(node1, node2, node3);
JavaFX provides a variety of layout panes to simplify the process of designing user interfaces. By incorporating these layout panes, developers can create effective and responsive user interfaces with ease.