title: Placing buttons in a specified location using swing in java
body: <p>I am trying to learn how to make JAVA programs and I am working with Swing. I am trying to place a button in the top left corner of the window and it keeps going to the top center.</p>
  
  <pre><code>public void createGUI(){
      JFrame frame = new JFrame("My Project");
      frame.setDefaultCloseOperation(3);
      frame.setSize(400, 350);
      frame.setVisible(true);
  
      JPanel panel = new JPanel();
  
      frame.add(panel);
  
      addButtonGUI(panel, new JButton(), "test", 1, 1);
  }
  
  public void addButtonGUI(JPanel panel, JButton button, String text, int x, int y){
      GridBagConstraints gbc = new GridBagConstraints();
      button.setText(text);
      button.setEnabled(true);
      gbc.gridx = x;
      gbc.gridy = y;
      gbc.gridwidth = 2;
      gbc.weightx = 1.0D;
      gbc.fill = 2;
      panel.add(button, gbc);
  }
  </code></pre>
  
  <p>What am I doing wrong or is there a better way to do this?
  Please help</p>