title: Java Swing GridBagLayout - adding buttons without space
body: <p>How can I remove spacing caused by gridBagLayout and make them stick together?<br>
  Here is my code simply adding 3 buttons.
  I read this question but there was no complete solution  <a href="https://stackoverflow.com/questions/17972904/how-to-fix-gap-in-gridbaglayout">How to fix gap in GridBagLayout</a>;<br>
  I just want to put all of my buttons on the top of the JFrame.</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.GridBagConstraints;
  import java.awt.GridBagLayout;
  
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  public class MyProblem {
  
      private JFrame frame = new JFrame();
  
      public static void main(String[] args) {
          new MyProblem();
      }
  
      public MyProblem() {
          frame.setLayout(new GridBagLayout());
          GridBagConstraints gc = new GridBagConstraints();
          gc.weightx = 1;
          gc.weighty = 1;
          gc.gridx = 0;
          gc.gridy = 0;
          gc.fill = GridBagConstraints.HORIZONTAL;
          gc.anchor = GridBagConstraints.NORTH;
          for (int i = 0; i &lt; 3; i++) {
              JPanel jPanel = new JPanel(new BorderLayout());
              jPanel.setSize(80, 80);
              jPanel.add(new JButton("Button " + i),BorderLayout.PAGE_START);
              frame.add(jPanel, gc);
              gc.gridy++;
          }
  
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(500, 500);
          frame.setVisible(true);
      }
  
  }
  </code></pre>
  
  <p><strong>How my buttons look like:</strong><br>
  <img src="https://i.stack.imgur.com/ublAq.png" alt="enter image description here"><br>
  <strong>How I want my buttons to look like:</strong>
  <img src="https://i.stack.imgur.com/xvgTc.png" alt="enter image description here"></p>