title: Multiple JPanel with different width inside a JFrame using GridBagLayout
body: <p>I'm trying to create two panels with different width in a JFrame. I want my right panel to have twice the width of my left panel. I'm trying to use GridBagLayout by using gridwidth = 1 for my leftpanel and gridwidth = 2 for my rightpanel. But instead of getting different width, I'm getting two panels with same width. What should I change? Any help would be appreciated.</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class AppFrame2 extends JFrame {
  
      GridBagLayout gbl;
      GridBagConstraints gbc;
      JPanel leftpanel;
      JPanel rightpanel;
  
      public AppFrame2() {
          this.setSize(500, 500);
          this.setResizable(false);
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          this.setVisible(true);
          this.getContentPane().setBackground(Color.BLACK);
  
          // Settning Frame Layout
          gbl = new GridBagLayout();
          gbc = new GridBagConstraints();
          this.setLayout(gbl);
  
          gbc.fill = GridBagConstraints.BOTH;
          gbc.weightx = 1.0;
          gbc.weighty = 1.0;
  
          // Add Panels
          leftpanel = new JPanel();
          leftpanel.setBackground(Color.green);
          this.addPanels(0, 0, 1, 1, leftpanel); // row, col, height, width component
  
          rightpanel = new JPanel();
          rightpanel.setBackground(Color.red);
          this.addPanels(0, 1, 1, 2, rightpanel);
      }
  
      private void addPanels(int row, int col, int height, int width,
          Component com) {
          gbc.gridx = col;
          gbc.gridy = row;
          gbc.gridheight = height;
          gbc.gridwidth = width;
          gbl.setConstraints(com, gbc);
          this.getContentPane().add(com);
      }
  
      public static void main(String[] args) {
          new AppFrame2();
      }
  
  }
  </code></pre>