How to center a Window in Java?

awt, java, swing, user-interface

Solution

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.

Problem

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

Original source