title: Centering a jFrame
body: <p>I'm trying to locate my frames at the center of the screen , I know that this code must work well:</p>
  
  <pre><code>Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
  int x = (int) ((screen.getWidth() - getWidth()) /2);
  int y = (int) ((screen.getHeight() -getHeight()) /2);
  setLocation(x, y); 
  </code></pre>
  
  <p>or this one :</p>
  
  <pre><code>Toolkit tk = Toolkit.getDefaultToolkit();
  Dimension screenSize = tk.getScreenSize();
  int screenHeight = screenSize.height;
  int screenWidth = screenSize.width;
  setSize(screenWidth / 2, screenHeight / 2);
  setLocation(screenWidth / 4, screenHeight / 4);
  </code></pre>
  
  <p>I have tried all the possible codes but I don't know why they don't work, the just move the frame to the bottom right corner of the screen I have used setRelative to null but again it doesn't work.</p>
  
  <p>I could finally bring the frame very close to the center by multiplying the width by 5 and dividing it by something but I know that this is not the right way.</p>
  
  <p>could anyone please explain to me what could be wrong ?</p>
  
  <p>Problem Fixed :</p>
  
  <p>solution:
  I found the best way myself , if you ever come up with the same problem simply let the netbeans do that automatically by going to properties and checking generate center , forget about the stupid codes.</p>