Java JDialog Center setDialogCenter(JDialog frame)

Here you can find the source of setDialogCenter(JDialog frame)

Description

set Dialog Center

License

Open Source License

Declaration

public static void setDialogCenter(JDialog frame) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

import javax.swing.JDialog;

public class Main {
    public static void setDialogCenter(JDialog frame) {
        Dimension screenSize = new Dimension(Toolkit.getDefaultToolkit().getScreenSize());
        Dimension windowSize = new Dimension(frame.getPreferredSize());
        int wdwLeft = screenSize.width / 2 - windowSize.width / 2;
        int wdwTop = screenSize.height / 2 - windowSize.height / 2;
        frame.pack();/*from   w ww  .ja v  a 2 s  .  c  o  m*/
        frame.setLocation(wdwLeft, wdwTop);
    }
}

Related

  1. getCentralDialogLocation(Component parent, JDialog dialog)
  2. getCentredDialogBounds(JDialog dialog, Component parent, int defaultWidth, int defaultHeight)
  3. packAndCenterJDialog(JDialog form)
  4. packInCenter(JDialog dialog)
  5. resizeAndCenter(JDialog dialog, double factor)
  6. setDialogWindowToCenter(JDialog dialog)
  7. showCenteredDialog(final JDialog dialog)