static int centerTopFrame_inset = 20; static JFrame centerTopFrame(JFrame frame) { frame.setLocationRelativeTo(null); // magic trick frame.setLocation(frame.getLocation().x, centerTopFrame_inset); ret frame; }