Here you can find the source of centerDialog(final JDialog target)
Parameter | Description |
---|---|
target | a parameter |
public static void centerDialog(final JDialog target)
//package com.java2s; //License from project: Apache License import javax.swing.*; import java.awt.*; public class Main { /**/* w w w . j a v a 2s .c om*/ * Centers JDialog on screen * * @param target */ public static void centerDialog(final JDialog target) { final Rectangle screen = getScreenRect(); final Rectangle frameSize = target.getBounds(); final int x = (screen.width - frameSize.width) / 2; final int y = (screen.height - frameSize.height) / 2; target.setLocation(x, y); } /** * Gers screen rectangle * * @return */ private static Rectangle getScreenRect() { final Rectangle screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().getBounds(); return screen; } }