I am trying to organize things in an custom JDialog using GridBagLayout and GridBagConstraints but so far it isn't working. The only thing I am trying to do right now is get a JLabel to stay centered at the top of the JDialog window no matter what. The only problem is that when I resize the JDialog the label stays in the center of the JDialog and not at the top. Im not sure what I am doing wrong. Here is how I am trying to get it to stay:
Java Code:
public class OptionsPanel extends JDialog
{
   public OptionsPanel()
   {
      JPanel panel = new JPanel();
      JLabel label = new JLabel("Options",0);
      GridBagLayout layout = new GridBagLayout();
      GridBagConstraints c = new GridBagConstraints();
      c.gridwidth = 3;
      c.gridx = 1;
      c.gridy = 0;
      layout.setConstraints(panel,c);
      panel.setLayout(layout);
      panel.add(label,c);

      setTitle("Options");
      add(panel);
      pack();
      setLocationRelativeTo(null);
   }
}

Then to show the Dialog I just call:
Java Code:
new OptionsPanel().setVisible(true);