JavaSwing_1.1:FlowLayout(フローレイアウト)


このリンクは次のとおりです.http://blog.csdn.net/xietansheng/article/details/72814541
Java Swingグラフィックインタフェース開発(ディレクトリ)
1.概要
公式Java DocsApi:java.awt.FlowLayout FlowLayout、フローレイアウトマネージャ.コンポーネントを水平方向に順番に並べ、1行いっぱいに並べ、次の行に並べ替えて並べ続けます.配列方向(左から右または右から左)は、容器のcomponentOrientation属性(この属性はComponentに属する)に依存し、次の値が可能です.
  • ComponentOrientation.LEFT_TO_RIGHT(デフォルト)
  • ComponentOrientation.RIGHT_TO_LEFT

  • 同じ行(水平方向)のコンポーネントの位置合わせは、FlowLayoutのalign属性によって決定されます.この値は次のようになります.
  • FlowLayout.LEFT:左揃え
  • FlowLayout.CENTER:中央揃え(デフォルト)
  • FlowLayout.RIGHT:右揃え
  • FlowLayout.LEADING:容器方向の開始辺に揃える、例えば左から右方向に対して左に揃える
  • .
  • FlowLayout.TRAILING:容器方向の終端エッジに整列し、例えば左から右方向に対して右に整列する.
  • FlowLayoutの構成方法:
    //         ,         5    
    FlowLayout()
    
    //       ,            5    
    FlowLayout(int align)
    
    //       ,          
    FlowLayout(int align, int hgap, int vgap)
    

    2.コードインスタンス
    package com.xiets.swing;
    
    import javax.swing.*;
    import java.awt.*;
    
    public class Main {
    
        public static void main(String[] args) {
            JFrame jf = new JFrame("    ");
            jf.setSize(200, 250);
            jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            jf.setLocationRelativeTo(null);
    
            //       ,         
            JPanel panel = new JPanel(new FlowLayout());
    
            JButton btn01 = new JButton("  01");
            JButton btn02 = new JButton("  02");
            JButton btn03 = new JButton("  03");
            JButton btn04 = new JButton("  04");
            JButton btn05 = new JButton("  05");
    
            panel.add(btn01);
            panel.add(btn02);
            panel.add(btn03);
            panel.add(btn04);
            panel.add(btn05);
    
            jf.setContentPane(panel);
            jf.setVisible(true);        // PS:          (  ),            
        }
    
    }
    

    結果:
    JavaSwing_1.1: FlowLayout(流式布局)_第1张图片