javaGUI–浮动布局(FlowLayOut)

java
Author

dd21

Published

December 5, 2022

package cn.usts.edu.lesson01;

import java.awt.*;

public class TestFlowLayOut {

    public static void main(String[] args) {
        // 窗口
        Frame frame = new Frame("myFlowLayOut");

        // 按钮
        Button button1 = new Button("button1");
        Button button2 = new Button("button2");
        Button button3 = new Button("button3");
        Button button4 = new Button("button4");

        frame.setSize(350,350);
        frame.setVisible(true);

        // 设置流失布局(默认居中)
        frame.setLayout(new FlowLayout());
        frame.add(button1);
        frame.add(button2);
        frame.add(button3);
        frame.add(button4);
    }
}

在这里插入图片描述
// 左对齐(右对齐......)
frame.setLayout(new FlowLayout(FlowLayout.LEFT));

在这里插入图片描述