import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JFrame; public static void CenterWindow(JFrame window) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int screenWidth = (int) screenSize.getWidth(); int screenHeight = (int) screenSize.getHeight(); window.setLocation(screenWidth / 2 - window.getWidth() / 2, screenHeight / 2 - window.getHeight() / 2); }