How to center a Java JDialog
Java/Swing FAQ: How do I center a JDialog?
Answer: The answer here really depends on what you mean by "center". If you really want to center a JDialog on screen, you can use code like this:
// center a jdialog on screen JDialog d = new JDialog(); d.setSize(400, 300); d.setLocationRelativeTo(null); d.setVisible(true);
By calling setLocationRelativeTo with null
, the JDialog will be centered.