title: Java Component alignment to top left corner
body: <p>I want to align my two of my components to the top left corner of the window.</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Font;
  import java.awt.GridBagConstraints;
  import java.awt.GridBagLayout;
  import java.awt.Insets;
  
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.SwingConstants;
  import javax.swing.border.EmptyBorder;
  
  public class MainFrame extends JFrame {
      public MainFrame() {
      JPanel mainPanel = new JPanel(new BorderLayout());
      JPanel gridbagPanel = new JPanel();
      this.setLayout(new BorderLayout());
  
      gridbagPanel.setLayout(new GridBagLayout());
      GridBagConstraints gc = new GridBagConstraints();
  
      JLabel nameLabel = new JLabel(player.getName());
      nameLabel.setHorizontalAlignment(SwingConstants.CENTER);
      nameLabel.setFont(new Font("Serif",Font.PLAIN,24));
      mainPanel.add(nameLabel, BorderLayout.NORTH);
  
      JLabel money = new JLabel("Pinigai: "+new Integer(player.getMoney()).toString());
      gc.gridx = 0;
      gc.gridy = 0;
      gc.anchor = GridBagConstraints.PAGE_START;
      gc.insets = new Insets(2,0,0,2);
      gridbagPanel.add(money,gc);
  
      JLabel job = new JLabel("Darbas: "+new Integer(player.getSkin()).toString());
      gc.gridx = 0;
      gc.gridy = 1;
      gc.insets = new Insets(2,0,0,2);
      gc.anchor = GridBagConstraints.LINE_START;
      gridbagPanel.add(job, gc);
  
      mainPanel.setBorder(new EmptyBorder(10,10,10,10));
      mainPanel.add(gridbagPanel,BorderLayout.WEST);
  
      add(mainPanel);
      getContentPane().revalidate();
  }
  </code></pre>
  
  <p>}
  It currently looks like this: <img src="https://i.stack.imgur.com/af8gp.png" alt="Current view of the components"></p>
  
  <p>And I would like the lines with numbers in the top left corner.</p>
  
  <p>Note that I'm aware that both JFrame("this" class) and the mainPanel are using BorderLayouts.</p>
  
  <p>Another non-related question: When should I create a new <code>GridBagConstraints</code> object? Why can't I just store one in a private instance variable for all usage needed?</p>