【Java】javafx界面布局

目录

一、面板类

(1)Pane面板

(2)HBox面板

(3)VBox面板

(4)BorderPane面板

(5)FlowPane面板

(6)GridPane面板

(7)StackPane面板

二、Color类和Font类

​三、Line类(直线)

四、Text类


一、面板类

(1)Pane面板
package com.javafx;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;


public class Panex extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        Circle circle=new Circle(25, Color.LIGHTCORAL);
        circle.setCenterX(100);
        circle.setCenterY(50);
        Rectangle rectangle=new Rectangle(100,40,Color.LIGHTBLUE);
        rectangle.relocate(100,50);
        //旋转
        rectangle.setRotate(-33);
        Pane pane=new Pane(circle,rectangle);
       // pane.getChildren().addAll(circle, rectangle);
        Scene scene=new Scene(pane,300,200);
        primaryStage.setTitle("面板图形");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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

(2)HBox面板

实现水平排列的控件框

package com.javafx;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.scene.control.Button;

public class HBox2 extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        Button button1=new Button("确定");
        Button button2=new Button("取消");
        //设置按钮大小
        button1.setPrefSize(200,20);
        button2.setPrefSize(100,20);

        HBox hBox=new HBox(button1,button2);
        //水平框中内容与边界之间的距离(上、右、下、左)
        hBox.setPadding(new Insets(15,12,15,12));
        //水平框中控件之间的距离
        hBox.setSpacing(10);

        Scene scene=new Scene(hBox,300,50);
        primaryStage.setTitle("HBxo");
        primaryStage.setScene(scene);
        primaryStage.show();

    }

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

(3)VBox面板

实现垂直排列的控件框

package com.javafx;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class VBox2 extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        Button red=new Button("红色");
        Button green=new Button("绿色");
        Button blue=new Button("蓝色");
        Button yellow=new Button("黄色");
        blue.setPrefSize(100,20);

        VBox vBox=new VBox(red,green,blue,yellow);
        //设置控制框居中对齐
        vBox.setAlignment(Pos.CENTER);
        //垂直框之间的距离
        vBox.setSpacing(20);

        Scene scene=new Scene(vBox,300,200);
        primaryStage.setTitle("
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值