Java – How to center a Window in Java

awtjavaswinguser interface

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

Best Answer

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.