Here you can find the source of makeCenter(JDesktopPane desktop)
public static void makeCenter(JDesktopPane desktop)
//package com.java2s; //License from project: Apache License import java.awt.Component; import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JDesktopPane; import javax.swing.JInternalFrame; public class Main { public static void makeCenter(Component component) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = component.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; }// w w w. j a v a 2 s . c o m if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } component.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); } public static void makeCenter(JDesktopPane desktop) { JInternalFrame[] frames = desktop.getAllFrames(); for (JInternalFrame frame : frames) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setFrameIcon(null); frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); } } }