title: Why does GridBagLayout center my components instead of putting it in the corner?
body: <p>So far I managed to avoid using the <code>GridBagLayout</code> (by hand code) as much as possible, but I could not avoid it this time and I am reading the SUN's tutorial <a href="http://download.oracle.com/javase/tutorial/uiswing/layout/gridbag.html">GridBagLayout</a>
  So far it is not going well. I think I am missunderstanding something.<br>
  For example I try the following code (similar to the one in SUN's post):  </p>
  
  <pre><code>public class MainFrame extends JFrame { 
  
  
      public static void main(String args[]) {
          EventQueue.invokeLater(new Runnable() {
              public void run() {
                  try {
                      MainFrame frame = new MainFrame();
                      frame.setVisible(true);
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          });
      }
  
      /**
       * Create the frame
       */
      public MainFrame() {
          super();
          setBounds(100, 100, 500, 375);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
          Container mainContainer = getContentPane();
  
          mainContainer.setLayout(new GridBagLayout());       
  
          //add label
          JLabel someLabel = new JLabel("Label 1:");
          GridBagConstraints constraints = new GridBagConstraints();
  
          constraints.gridx = 0;
          constraints.gridy = 0;
          //constraints.anchor = GridBagConstraints.FIRST_LINE_START;
          //constraints.weightx = 0.5;
          mainContainer.add(someLabel, constraints);      
  
          JTextField someText = new JTextField(30);
  
          constraints = new GridBagConstraints();
  
          constraints.gridx = 1;
          constraints.gridy = 0;
          constraints.weightx = 0.5;
          mainContainer.add(someText, constraints);
  
          //
      }
  
  }
  </code></pre>
  
  <p>I get the label and the textfield one next to the other in the <strong>center</strong> of the frame.<br>
  But I was expecting that they would show up in the top left corner since the gridx and gridy is 0 for the label.<br>
  Even if I set <code>constraints.anchor = GridBagConstraints.FIRST_LINE_START;</code> still the same result.<br>
  Am I wrong here?<br>
  From the SUN's post:  </p>
  
  <blockquote>
    <p>Specify the row and column at the upper left of the component. The
    leftmost column has address gridx=0 and the top row has address
    gridy=0.</p>
  </blockquote>