流布局, FlowLayout(FlowLayout.TRAILING)

package com.company;

import javax.swing.*;
import java.awt.*;

public class Main extends JFrame {
    Main(){
        setBounds(100,100,300,200);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        Container c=getContentPane();
        c.setLayout(new FlowLayout(FlowLayout.RIGHT,20,20));//给容器设置流布局
        /*
        FlowLayout.CENTER-----中心对齐;
        FlowLayout.LEADING-----顶对齐;
        FlowLayout.LEFT--------左对齐;
        FlowLayout.RIGHT-------右对齐;
        FlowLayout.TRAILING----排序对齐;
         */
        for (int i=1;i<10;i++){
            c.add(new JButton("按钮"+i));
        }
        setVisible(true);

 

    }

    public static void main(String[] args) {
         new  Main();
	// write your code here
    }
}

 

 

 

posted @ 2018-12-08 17:12  逐梦武威  阅读(876)  评论(0编辑  收藏  举报