1. 程式人生 > >流布局, FlowLayout(FlowLayout.TRAILING)

流布局, FlowLayout(FlowLayout.TRAILING)

etc http opera void etl clas idt lead imp

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
    }
}

技術分享圖片

技術分享圖片

流布局, FlowLayout(FlowLayout.TRAILING)