Java JDialog Center center(JDialog dialog)

Here you can find the source of center(JDialog dialog)

Description

Center JDialog.

License

Open Source License

Declaration

public static void center(JDialog dialog) 

Method Source Code

//package com.java2s;

import javax.swing.JFrame;
import javax.swing.JDialog;

import java.awt.Dimension;
import java.awt.Toolkit;

public class Main {
    /**/*from   w  ww  .j av  a2 s .c  om*/
     * Center JFrame.
     */
    public static void center(JFrame frame) {
        Dimension frameSize = frame.getSize();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation((screenSize.width - frameSize.width) >> 1, (screenSize.height - frameSize.height) >> 1);
    }

    /**
     * Center JDialog.
     */
    public static void center(JDialog dialog) {
        Dimension dialogSize = dialog.getSize();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        dialog.setLocation((screenSize.width - dialogSize.width) >> 1,
                (screenSize.height - dialogSize.height) >> 1);
    }
}

Related

  1. center(JDialog frame)
  2. centerDialog(final JDialog target)
  3. centerDialog(javax.swing.JDialog dialog)
  4. centerDialog(JDialog dDialog)