package com.test;
import javax.swing.*;
import java.awt.*;
/**
* @Author:xiexu
* @Date:2023/12/4 8:54
*/
public class FlowLayoutTest extends JFrame {
public FlowLayoutTest() {
super("测试流布局");
// 面板: jPanel默认的布局方式就是流布局!
JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 80, 30)); // 水平,垂直
JButton jButton1 = new JButton("测试按钮1");
JButton jButton2 = new JButton("测试按钮2");
JButton jButton3 = new JButton("测试按钮3");
JButton jButton4 = new JButton("测试按钮4");
JButton jButton5 = new JButton("测试按钮5");
JButton jButton6 = new JButton("测试按钮6");
Container contentPane = getContentPane();
jPanel.add(jButton1);
jPanel.add(jButton2);
jPanel.add(jButton3);
jPanel.add(jButton4);
jPanel.add(jButton5);
jPanel.add(jButton6);
contentPane.add(jPanel);
setSize(600, 400);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
setVisible(true);
}
public static void main(String[] args) {
new FlowLayoutTest();
}
}
Java+Swing: (FlowLayout流布局) 整理3
于 2023-12-04 10:44:45 首次发布