Here you can find the source of centerFrameTo(final JFrame frameToCenter, final Dimension orientDim)
public static void centerFrameTo(final JFrame frameToCenter, final Dimension orientDim)
//package com.java2s; //License from project: Apache License import java.awt.Dimension; import javax.swing.JFrame; public class Main { public static void centerFrameTo(final JFrame frameToCenter, final Dimension orientDim) { Dimension frameSize = frameToCenter.getSize(); int x = (orientDim.width - frameSize.width) / 2; int y = (orientDim.height - frameSize.height) / 2; frameToCenter.setLocation(x, y); }// w w w.j ava 2 s . c o m }