How to center a Window in Java?

Andrew Swan picture Andrew Swan · Sep 28, 2008 · Viewed 196k times · Source

What's the easiest way to centre a java.awt.Window, such as a JFrame or a JDialog?

Answer

Andrew Swan picture Andrew Swan · Sep 28, 2008

From this link

If you are using Java 1.4 or newer, you can use the simple method setLocationRelativeTo(null) on the dialog box, frame, or window to center it.