📜  JavaFX borderpane

📅  最后修改于: 2020-10-14 05:49:16             🧑  作者: Mango

JavaFX BorderPane

BorderPane将节点排列在屏幕的左,右,中心,顶部和底部。它由javafx.scene.layout.BorderPane类表示。此类提供了各种方法,例如setRight(),setLeft(),setCenter(),setBottom()和setTop(),这些方法用于设置指定节点的位置。我们需要实例化BorderPane类以创建BorderPane布局。

物产

下表列出了BorderPane类的属性及其setter方法。

Type Property Setter Methods Description
Node Bottom setBottom() Add the node to the bottom of the screen
Node Centre setCentre() Add the node to the centre of the screen
Node Left setLeft() Add the node to the left of the screen
Node Right setRight() Add the node to the right of the screen
Node Top setTop() Add the node to the top of the screen

建设者

该类中有以下构造函数。

  • BorderPane():创建空布局
  • BorderPane(Node Center):使用中心节点创建布局
  • BorderPane(节点中心,节点顶部,节点右侧,节点底部,节点左侧):使用所有节点创建布局

package application;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.stage.Stage;
public class Label_Test extends Application {

@Override
public void start(Stage primaryStage) throws Exception {
BorderPane BPane = new BorderPane();
BPane.setTop(new Label("This will be at the top"));
BPane.setLeft(new Label("This will be at the left"));
BPane.setRight(new Label("This will be at the Right"));
BPane.setCenter(new Label("This will be at the Centre"));
BPane.setBottom(new Label("This will be at the bottom"));
Scene scene = new Scene(BPane,600,400);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}

}