flowlayout java_Java FlowLayout

Java FlowLayout

1 Java FlowLayout的介绍

FlowLayout用于将组件依次排成一行(在流中)。它是小程序或面板的默认布局。

2 Java FlowLayout的字段

public static final int LEFT

public static final int RIGHT

public static final int CENTER

public static final int LEADING

public static final int TRAILING

3 Java FlowLayout的构造方法

构造方法

描述

FlowLayout()

创建具有居中对齐和默认5单位的水平和垂直间隙的流布局。

FlowLayout(int align)

创建具有给定对齐方式和默认5单位的水平和垂直间隙的流布局。

FlowLayout(int align, int hgap, int vgap)

创建具有给定对齐方式和给定水平和垂直间隙的流布局。

4 Java FlowLayout的案例

package com.yiidian;

/**

* 一点教程网: http://www.yiidian.com

*/

import java.awt.*;

import javax.swing.*;

public class MyFlowLayout{

JFrame f;

MyFlowLayout(){

f=new JFrame();

f.setTitle("FlowLayout案例-一点教程网");

JButton b1=new JButton("1");

JButton b2=new JButton("2");

JButton b3=new JButton("3");

JButton b4=new JButton("4");

JButton b5=new JButton("5");

f.add(b1);f.add(b2);f.add(b3);f.add(b4);f.add(b5);

f.setLayout(new FlowLayout(FlowLayout.RIGHT));

//setting flow layout of right alignment

f.setSize(300,300);

f.setVisible(true);

}

public static void main(String[] args) {

new MyFlowLayout();

}

}

输出结果为:

45269ddf0c1566a61c3d9370b9b4ff64.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值