JavaFX- BorderPane

 先来两张效果图::

 

package sample;


import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.*;
import javafx.stage.Stage;


public class Main extends Application {


    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        Button button = new Button("button");

        AnchorPane a1 = new AnchorPane();
        AnchorPane a2 = new AnchorPane();
        AnchorPane a3 = new AnchorPane();
        AnchorPane a4 = new AnchorPane();
        AnchorPane a5 = new AnchorPane();
        a1.setStyle("-fx-background-color: darkturquoise");
        a1.setPrefHeight(50);
        a1.setPrefWidth(50);
        a2.setStyle("-fx-background-color: #a15252");
        a2.setPrefHeight(100);
        a2.setPrefWidth(100);
        a3.setStyle("-fx-background-color: #c78441");
        a3.setPrefHeight(300);
        a3.setPrefWidth(300);
        a4.setStyle("-fx-background-color: #5d7433");
        a4.setPrefHeight(100);
        a4.setPrefWidth(100);
        a5.setStyle("-fx-background-color: #088de5");
        a5.setPrefHeight(100);
        a5.setPrefWidth(100);

        BorderPane bp = new BorderPane();
        bp.setStyle("-fx-background-color: #6b11ac");
       /* //给各个方位安插anchor
        bp.setTop(button);//在TOP放一个按钮
        //获得组件,在top的button叫啥
        Button bu = (Button) bp.getTop();
        System.out.println(bu.getText());
        */
        bp.setTop(a1);
        bp.setBottom(a2);//注释后会将下面的面板去掉,从而使得左右面板直接垂直下去。
        bp.setCenter(a3);当不指定宽高时,center的权限最高,会铺满整个屏幕。
        bp.setLeft(a4);
        bp.setRight(a5);


        //三个重要方法::内边距、外边距、对齐方式


        bp.setPadding(new Insets(5));//内边距

        bp.setMargin(a1, new Insets(5));//设置a1的外边距

        bp.setAlignment(button, Pos.BOTTOM_CENTER);


        Scene scene = new Scene(bp);


        primaryStage.setScene(scene);
        primaryStage.setTitle("Java FX Lesson16.BorderPane ");
        primaryStage.setWidth(800);
        primaryStage.setHeight(800);
        primaryStage.show();


    }


}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值