个性化阅读
专注于IT技术分析

JavaFX BorderPane

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

属性

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

类型 属性 设置方法 描述
Node Bottom setBottom() 将节点添加到屏幕底部
Node Centre setCentre() 将节点添加到屏幕中心
Node Left setLeft() 将节点添加到屏幕左侧
Node Right setRight() 将节点添加到屏幕右侧
Node Top setTop() 将节点添加到屏幕顶部

建设者

该类中有以下构造函数。

  1. BorderPane():创建空布局
  2. BorderPane(Node Center):使用中心节点创建布局
  3. 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);
	}
	
}
JavaFX BorderPane输出
赞(0)
未经允许不得转载:srcmini » JavaFX BorderPane

相关推荐

评论 抢沙发

评论前必须登录!