大きな正方形を作る 4 つの正方形と、その下にあるボタンが正方形全体に広がるレイアウトを作成しようとしています。
正方形を完璧に作成したところを試しGridLayout
てみましたが、ボタンが画面全体に伸びませんでした。
私もやってみGridBagLayout
ましたが間隔があって四角が小さくてダメでした。
PS: ボタンは、正方形の場合は button1、button2、button3、button4、下のボタンの場合は start です。
また、正方形を400x400にしたいです。
私のコードGridLayout
:
this.setLayout(new GridLayout(3,2));
button1 = new JButton();
//button1.setBackground(Color.green);
button1.setBounds(0, 0, 200, 200);
button2 = new JButton();
//button2.setBounds(0, 200, 200, 200);
button2.setBackground(Color.red);
button3 = new JButton();
//button3.setBackground(Color.yellow);
button3.setBounds(200, 0, 200, 200);
button4 = new JButton();
//button4.setBounds(200, 200, 200, 200);
button4.setBackground(Color.blue);
start = new JButton("Start");
//start.setBounds(300, 300, 100, 100);
this.add(button1);
this.add(button2);
this.add(button3);
this.add(button4);
this.add(start);