Center a JFrame
import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JFrame; public class Main extends JFrame { public static void main(String[] args) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Main mainForm = new Main(); mainForm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainForm.setSize(250, 250); mainForm.setLocation((screenSize.width - mainForm.getWidth()) / 2, (screenSize.height - mainForm.getHeight()) / 2); mainForm.pack(); mainForm.setVisible(true); } }