title: GridBagLayout elements are overlapped in grid Y
body: <p>I am learning how to use <code>GridBagLayout</code> from Java Swing...</p>
  <p>In this example I want to put 4 elements in each row as you can see in my code:</p>
  <pre><code>        this.setLayout(new GridBagLayout());
          GridBagConstraints constraints = new GridBagConstraints();
          
          constraints.gridx = 0;
          constraints.gridy = 0;
          constraints.gridwidth = 1;
          constraints.gridheight = 1;
          //constraints.weighty = 1;
          constraints.anchor = GridBagConstraints.NORTHWEST;
          constraints.fill = constraints.HORIZONTAL;
          this.add(label1, constraints);
          constraints.weighty = 0.0; 
          
          constraints.gridx = 1;
          constraints.gridy = 1;
          constraints.gridwidth = 0;
          constraints.gridheight = 1;
          constraints.weighty = 1;
          constraints.anchor = GridBagConstraints.CENTER;
          constraints.fill = constraints.BOTH;
          this.add(label, constraints);
          constraints.weighty = 0.0; 
          
          JLabel precio = new JLabel();
          precio.setText(&quot;Precio    12345.5&quot;);
          constraints.gridx = 0;
          constraints.gridy = 2;
          constraints.gridwidth = 2;
          constraints.gridheight = 2;
          constraints.weighty = 1;
          constraints.fill = constraints.HORIZONTAL;
          constraints.anchor = GridBagConstraints.NORTH;
          this.add(precio, constraints);
          constraints.weighty = 0.0; 
          
          JLabel cantidad = new JLabel();
          cantidad.setText(&quot;Cantidad    &quot;);
          constraints.gridx = 0;
          constraints.gridy = 3;
          constraints.gridwidth = 2;
          constraints.gridheight = 2;
          constraints.weightx = 1;
          constraints.fill = constraints.HORIZONTAL;
          constraints.anchor = GridBagConstraints.NORTH;
          this.add(cantidad, constraints);
          constraints.weighty = 0.0; 
          
          JTextField textfield = new JTextField();
          textfield.setPreferredSize(new Dimension(100 , 30));
          constraints.gridx = 2;
          constraints.gridy = 3;
          constraints.gridwidth = 2;
          constraints.gridheight = 2;
          constraints.weighty = 1;
          constraints.fill = constraints.HORIZONTAL;
          this.add(textfield, constraints);
          constraints.weighty = 0.0; 
          
          JButton boton = new JButton();
          boton.setText(&quot;Agregar&quot;);
          constraints.gridx = 0;
          constraints.gridy = 4;
          constraints.gridwidth = 2;
          constraints.gridheight = 2;
          constraints.weightx = 1;
          constraints.fill = constraints.HORIZONTAL;
          constraints.anchor = GridBagConstraints.NORTH;
          this.add(precio, constraints);
          constraints.weighty = 0.0; 
  </code></pre>
  <p>As you can see in the code.</p>
  <p>In the row 0, I want to put a JLabel</p>
  <p>In the row 1, I want to put a JLabel with an icon</p>
  <p>In the row 2, I want to put a JTextField</p>
  <p>In the row 3, I want to put a JTextfield and JTextField on the right
  side</p>
  <p>And finally in the row 4, I want to put a JButton on the center of
  the column.</p>
  <p>But I am getting this when I run the JFrame:</p>
  <p><a href="https://i.stack.imgur.com/e0FwP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e0FwP.png" alt="enter image description here" /></a></p>
  <p>Starting from the second row I am getting the components overlapped, and I don't know why.</p>
  <p>Maybe I am missing something from the <code>GridBagLayout</code> behaviour because I am still learning how to use it.</p>