コンストラクタ | 説明 | 引数 | 引数説明 |
---|---|---|---|
GridLayout() | 1×1 の GridLayout を作成 | - | - |
GridLayout(int rows, int cols) | 指定行&列数の GridLayout を作成 |
rows | 行数 |
cols | 列数 | ||
GridLayout(int rows, int cols, int hgap, int vgap) | 指定行&列数かつ 隙間を空けた GridLayout を作成 |
rows | 行数 |
cols | 列数 | ||
hgap | 水平方向間隔 | ||
vgap | 垂直方向間隔 |
import java.awt.BorderLayout; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; /** * LayoutManager サンプル05 * ・GridLayout * * @author みっちー */ public class LayoutManager05 extends JFrame { /** * 開始メソッド * * @param args パラメータ */ public static void main(String[] args){ LayoutManager05 frame = new LayoutManager05(); // 閉じるボタンをクリックされた場合の動作を設定 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // ウインドウのタイトルを設定 frame.setTitle("LayoutManager サンプル05[GridLayout]"); // フレームの X座標、Y座標、幅、高さを設定 frame.setBounds(100, 200, 480, 150); // フレームを表示(これをしないと透明のフレームが立ち上がってしまう) frame.setVisible(true); } /** * コンストラクタ */ public LayoutManager05() { // ベースとなるパネルを[GridLayout]として作成 // 2×3, 隙間ありで設定 JPanel panelBase = new JPanel(); panelBase.setLayout(new GridLayout(2, 3, 15, 5)); // ボタンを作成 JButton button1 = new JButton("AAAAA"); JButton button2 = new JButton("BBB"); JButton button3 = new JButton("CCCCC"); JButton button4 = new JButton("DDDDDDDD"); JButton button5 = new JButton("E"); // パネルにボタンを配置 panelBase.add(button1); panelBase.add(button2); panelBase.add(button3); panelBase.add(button4); panelBase.add(button5); // ベースパネルを追加 getContentPane().add(panelBase, BorderLayout.CENTER); } }
2016/05/13 Windows 8.1 + Java 7 環境で全体を見直し 2007/12/07 新規作成