Swing002——流式布局

一、api介绍

在这里插入图片描述
在这里插入图片描述

二、实例演示

package com.layoutflow;

import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class testFlowLayout {
	public static void main(String[] args) {
		// 1、创建一个顶层容器
		JFrame jFrame = new JFrame();
		// 设置标题
		jFrame.setTitle("流式布局");
		// 设置大小
		jFrame.setSize(500, 400);
		// 设置位置
		jFrame.setLocationRelativeTo(null);
		// 设置不能最大化
		jFrame.setResizable(false);
		// 设置关闭时推出虚拟机JVM
		jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// 2、创建一个中间容器(设置布局)
		JPanel jpane = new JPanel();
		// jpane.setLayout(new FlowLayout());// 默认为居中
		// jpane.setLayout(new FlowLayout(FlowLayout.RIGHT));// 居右
		// jpane.setLayout(new FlowLayout(FlowLayout.LEFT));// 居左
		jpane.setLayout(new FlowLayout(FlowLayout.CENTER, 30, 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");
		// 将按钮添加到中间容器中
		jpane.add(jButton1);
		jpane.add(jButton2);
		jpane.add(jButton3);
		jpane.add(jButton4);
		jpane.add(jButton5);
		jpane.add(jButton6);

		// 将中间容器添加到顶层容器中
		jFrame.add(jpane);

		// 显示窗口
		jFrame.setVisible(true);
	}
}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值