title: how to center position progressbar in java
body: <p>i want my progressbar at the center of the sreen. i already tried...</p>
  
  <pre><code>setLocationRelativeTo(null);
  </code></pre>
  
  <p>but when i run the program it didnt work. somehow it is not in the middle of the screen. Please help me. See image.</p>
  
  <p><img src="https://i.stack.imgur.com/tBY7z.png" alt="enter image description here"></p>
  
  <p><strong>HERE ARE MY CODES</strong></p>
  
  <pre><code>public class progressbar extends JFrame {
      private JProgressBar jp;
      private Timer t;
      int i = 0;
  
  public progressbar() {
  
      setTitle("Loading...");
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      getContentPane().setLayout(new GridBagLayout());
      setLocationRelativeTo(null);
      setUndecorated(true);
      setVisible(true);
      jp = new JProgressBar();
      // Paint the percent complete on progress bar
      jp.setStringPainted(true);
      jp.setPreferredSize(new Dimension(500, 30));
      jp.setMinimum(0);
      jp.setMaximum(1000);
      getContentPane().add(jp);
      pack();
      // Create a timer that executes for every 2 millisec
      t = new Timer(2, new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
              jp.setValue(i++);
              if (i == 1000) {
                  t.stop();
                  setVisible(false);
                  loginInterface l = new loginInterface();
                  l.txtUser.requestFocus();
              }
          }
      });
      // Start the timer
      t.start();
  }
  </code></pre>
  
  <p>The GridBagConstraints</p>
  
  <p>Anchor is Center, Grid Height 1, Grid Width 1, Grid X -1, Grid Y - 1</p>