JavaFX布局-BorderPane

  • 将容器空间分成五个区域:顶部(Top)、底部(Bottom)、左侧(Left)、右侧(Right)和中心(Center)。每个区域都可以放置一个节点(Node),比如另一个布局容器或UI控件
  • BorderPane中的一些区域可以为空,只设置需要的区域即可
  • 顶部和底部默认是横向扩展全宽的
  • 左右两侧则会扩展到足够容纳内容的高度
  • 中心区域通常用来放置主要的内容,默认会填充剩余的空间
    在这里插入图片描述

实现方式

Java实现

BorderPane pane = new BorderPane();
pane.setTop(new Label("top"));
pane.setCenter(new Label("center"));
pane.setBottom(new Label("bottom"));
pane.setLeft(new Label("left"));
pane.setRight(new Label("right"));
pane.setPadding(new Insets(5, 10, 10, 5));

FXML实现

<BorderPane xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml" prefHeight="400.0" prefWidth="600.0">
    <top>
        <Button text="top"/>
    </top>
    <center>
        <Button text="center"/>
    </center>
    <bottom>
        <Button text="bottom"/>
    </bottom>
    <left>
        <Button text="left"/>
    </left>
    <right>
        <Button text="right"/>
    </right>
</BorderPane>

综合案例

BorderPane pane = new BorderPane();
        // top
        MenuBar menuBar = new MenuBar();
        menuBar.setStyle("-fx-background-color: pink;");
        Menu file = new Menu("文件");
        file.getItems().add(new Menu("新建"));
        file.getItems().add(new Menu("打开"));
        menuBar.getMenus().add(file);
        menuBar.getMenus(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值