I am trying to make a layout that has 4 squares that make a larger square and a button beneath that stretches across the square.
I tried GridLayout
where I created the square perfectly but the button did not stretch across the screen.
I also tried GridBagLayout
but there was spacing and the square was small and it was bad.
PS: The buttons are button1, button2, button3, button4, for the square, and start for the bottom button.
Also I want the square to be 400x400.
My code with 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);