Java tutorial
//package com.java2s; import java.awt.Dimension; import java.awt.FileDialog; import java.awt.Point; import java.awt.Window; import javax.swing.JDialog; public class Main { public static void centreDialogOnWindow(Window owner, JDialog dialog) { Point ownerPosition = owner.getLocationOnScreen(); Dimension ownerSize = owner.getSize(); Dimension dialogSize = dialog.getSize(); int x = ownerPosition.x + (ownerSize.width / 2) - (dialogSize.width / 2); int y = ownerPosition.y + (ownerSize.height / 2) - (dialogSize.height / 2); dialog.setLocation(x, y); } public static void centreDialogOnWindow(Window owner, FileDialog dialog) { Point ownerPosition = owner.getLocationOnScreen(); Dimension ownerSize = owner.getSize(); Dimension dialogSize = dialog.getSize(); int x = ownerPosition.x + (ownerSize.width / 2) - (dialogSize.width / 2); int y = ownerPosition.y + (ownerSize.height / 2) - (dialogSize.height / 2); dialog.setLocation(x, y); } }