Java tutorial
//package com.java2s; import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JDialog; public class Main { private static final Toolkit toolkit = Toolkit.getDefaultToolkit(); /** * Resize a dialog to be a percentage of the total screen size * * @param owner * @param dialog * @param percentage */ public static void resizeAndCentreDialogOnScreen(JDialog dialog, double percentage) { Dimension screenSize = toolkit.getScreenSize(); int width = (int) ((screenSize.width * percentage) / 100d); int height = (int) ((screenSize.height * percentage) / 100d); dialog.setSize(width, height); int x = (int) ((screenSize.width * 0.5f) - (width * 0.5f)); int y = (int) ((screenSize.height * .05f) - (height * 0.5f)); dialog.setLocation(x, y); } }