Here you can find the source of centrarVentana(JDialog pDialog)
public static void centrarVentana(JDialog pDialog)
//package com.java2s; //License from project: Open Source License import javax.swing.*; import java.awt.*; public class Main { public static void centrarVentana(JDialog pDialog) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension objectSize = pDialog.getSize(); if (objectSize.height > screenSize.height) { objectSize.height = screenSize.height; }//from w ww . j a v a 2 s . c o m if (objectSize.width > screenSize.width) { objectSize.width = screenSize.width; } pDialog.setLocation((((screenSize.width - objectSize.width) / 2)), (screenSize.height - objectSize.height) / 2); } }