title: GridBagLayout and FlowLayout: Components appearing at unexpected positions
body: <p><strong>1. Question About GridBagLayout:-</strong>
  Inspite of setting <strong>gridx=0;</strong> for all the components, all of them are aligning in the center of the parent. <strong>Please tell me how to fix it and please do tell me why is this unexpected behavior occuring.</strong></p>
  
  <p><strong>2. Question About FlowLayout:-</strong></p>
  
  <ol>
  <li><p>In the start of the example, a panel (added to the top of the parent
  panel with the GridBagLayout) is using <code>FlowLayout</code>. According to
  the documentation, in the constructor <code>FlowLayout(FlowLayout.LEFT,
  5, 5)</code>, <code>FlowLayout.LEFT</code> is for <em>alignment</em>, next two <code>int</code>'s are
  for <code>hgap</code> and <code>vgap</code>. <strong>I am using Left alignment but still both
  the buttons appear in the center. Please tell me why?</strong></p></li>
  <li><p>The vertical inset of all the components is much more than expected. <strong>Why is that happening? The same value of 5 is not resulting in so much of an inset on the sides</strong> :s</p></li>
  </ol>
  
  <p><strong>EXAMPLE CODE:-</strong></p>
  
  <pre><code>Card(){
  
          setLayout(new GridBagLayout());
  
          JPanel panelBtns= new JPanel();
          panelBtns.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 5));
          JButton emailBtn= new JButton("a");
          JButton saveBtn= new JButton("b");
          panelBtns.add(emailBtn);
          panelBtns.add(saveBtn);
          GridBagConstraints c= new GridBagConstraints();
          c.gridx=0;
          c.gridy=0;
          c.insets= new Insets(5,5,5,5);
          c.weightx=1;
          c.weighty=1;
          add(panelBtns, c);
  
          JLabel labelTitle= new JLabel("Title");
          labelTitle.setFont(new Font("calibri", Font.PLAIN, 12));
          c= new GridBagConstraints();
          c.gridx=0;
          c.gridy=1;
          c.insets=new Insets(5,5,5,5);
          c.weightx=0.35;
          c.weighty=1;
          add(labelTitle, c);
  
          JTextField textField= new JTextField();
          Border border = BorderFactory.createLineBorder(Color.GRAY);
          textField.setBorder(BorderFactory.createCompoundBorder(border, 
                      BorderFactory.createEmptyBorder(2,2,2,2)));
          c= new GridBagConstraints();
          c.gridx=0;
          c.gridy=2;
          c.insets= new Insets(5,5,5,5);
          c.fill=c.HORIZONTAL;
          c.weightx= 1;
          c.weighty=1;
          add(textField,c); 
  
          JLabel bodyLabel= new JLabel("Detail");
          bodyLabel.setFont(new Font("calibri", Font.PLAIN, 12));
          c= new GridBagConstraints();
          c.gridx=0;
          c.gridy=3;
          c.insets=new Insets(5,5,5,5);
          c.weightx=1;
          c.weighty=1;
          add(bodyLabel, c);
  
          JTextArea textArea= new JTextArea();
          Border border1 = BorderFactory.createLineBorder(Color.GRAY);
          textArea.setBorder(BorderFactory.createCompoundBorder(border1, 
                      BorderFactory.createEmptyBorder(2,2,2,2)));
          c= new GridBagConstraints();
          c.gridx=0;
          c.gridy=4;
          c.insets= new Insets(5, 5, 5,5);
          c.fill=c.BOTH;
          c.weightx=1;
          c.weighty=10;
          add(textArea,c);
  
      }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/15cXQ.png" alt="enter image description here"></p>
  
  <hr>
  
  <p>EDIT:-</p>
  
  <p>I changed the values of insets but an <strong>unwanted inset above and under the components is still there</strong>...  It looks almost fine here because I used a small frame size for this screenshot, but when the frame is bigger, it looks ugly and misplaced. </p>
  
  <p>I want the gap between <code>panelBtns</code> and <code>titleLabel</code> to be less, and that ebtween the <code>textFielf</code> and the <code>titleLabel</code> even lesser... Likewise for <code>bodyLabel</code> and <code>textArea</code>.</p>
  
  <pre><code>c.insets= new Insets(2,2,0,2); // panelBtns
  c.insets=new Insets(0,5,0,5); //titleLabel
  c.insets= new Insets(0,5,0,5); //textField
  c.insets=new Insets(0,5,0,5); //bodyLabel
  c.insets= new Insets(0, 5, 5,5); //textArea
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/RHD7w.png" alt="enter image description here"></p>