Java JDialog Center centerDialog(final JDialog target)

Here you can find the source of centerDialog(final JDialog target)

Description

Centers JDialog on screen

License

Apache License

Parameter

Parameter Description
target a parameter

Declaration

public static void centerDialog(final JDialog target) 

Method Source Code


//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;
    }
}

Related

  1. center(JDialog dialog)
  2. center(JDialog frame)
  3. centerDialog(javax.swing.JDialog dialog)
  4. centerDialog(JDialog dDialog)
  5. centerDialog(JDialog dialog)
  6. centerDialog(JDialog dialog)