title: Placing button panel in center Java Swing
body: <p>I am new to swing and trying to make a simple quiz game just for practice reasons. What I want to make is like this: <a href="https://i.stack.imgur.com/dw7SG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dw7SG.jpg" alt="enter image description here"></a></p>
  
  <p>This was my first implementation but there I extends JFrame and make all of this in one frame then i realize i need to use cardlayout to change from the main menu to the playing scene so i split it to 1 class main frame and other classes for the mainmenu, play scene, game over scene, etc. So my MainMenu now extends JPanel and when I add buttons to the button panel and then add buttonpanel to the mainpanel i got this: </p>
  
  <p><a href="https://i.stack.imgur.com/dFr2m.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dFr2m.jpg" alt="enter image description here"></a></p>
  
  <p>Its like the panel containing label of the main menu and the button panel are next to each other but i need them like in the first picture. Here is my MainMenu class:</p>
  
  <pre><code>public class MainMenu extends JPanel{
  
  private JLabel menuTitle;
  private JPanel menuTitlePanel;
  private JPanel buttonPanel;
  
  public MainMenu(){
  
      this.setBackground(new Color(0, 128, 43));
  
      //ADDING THE TITLE
      menuTitle = new JLabel("&lt;html&gt;&lt;h1&gt;&lt;strong&gt;&lt;i&gt;Krisko Beatz Quiz&lt;/i&gt;&lt;/strong&gt;&lt;/h1&gt;&lt;hr&gt;&lt;/html&gt;");  
      menuTitle.setForeground(Color.BLACK);
  
      menuTitlePanel = new JPanel(new GridBagLayout());
      menuTitlePanel.setBackground(new Color(0, 128, 43));    
  
      GridBagConstraints gbcTitle = new GridBagConstraints();
      gbcTitle.weightx = 0;
      gbcTitle.weighty = 0;
      gbcTitle.gridx = 0;
      gbcTitle.gridy = 0;
      gbcTitle.gridwidth = 3;
      gbcTitle.insets = new Insets(70, 0, 0, 0);
  
      menuTitlePanel.add(menuTitle, gbcTitle);
      this.add(menuTitlePanel, BorderLayout.NORTH);
  
      buttonPanel = new JPanel(new GridBagLayout());
      buttonPanel.setBackground(new Color(0, 128, 43));
  
      JButton startButton = new JButton("Start");
  
      GridBagConstraints gbcStart = new GridBagConstraints();
      gbcStart.gridx = 1;
      gbcStart.gridy = 1;
      gbcStart.ipadx = 50;
      gbcStart.ipady = 10;
      gbcStart.gridwidth = 3;
      gbcStart.insets = new Insets(10, 0, 0, 0);
  
      buttonPanel.add(startButton, gbcStart);
      this.add(buttonPanel, BorderLayout.CENTER);
  
  
  
  }
  }
  </code></pre>
  
  <p>Any help will be appreciated.</p>