Java tutorial
//package com.java2s; import javax.swing.*; import java.awt.*; import java.util.prefs.Preferences; public class Main { public static void centerFrame(JFrame frame, Preferences prefs, int defWidth, int defHeight) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int w = (int) ((screenSize.getWidth() / 100) * defWidth); int h = (int) ((screenSize.getHeight() / 100) * defHeight); int x = (int) ((screenSize.getWidth() - w) / 2); int y = (int) ((screenSize.getHeight() - h) / 2); if (prefs != null) { frame.setBounds(prefs.getInt("x", x), prefs.getInt("y", y), prefs.getInt("w", w), prefs.getInt("h", h)); } else { frame.setBounds(x, y, w, h); } } }