Java JDialog Center centerWindow(JDialog dialog)

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

Description

center Window

License

Open Source License

Declaration

public static void centerWindow(JDialog dialog) 

Method Source Code


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

import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JDialog;

public class Main {
    public static void centerWindow(JFrame frame) {
        // Center the window
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = frame.getSize();
        if (frameSize.height > screenSize.height) {
            frameSize.height = screenSize.height;
        }/*www  .  j  av a2s .c  om*/
        if (frameSize.width > screenSize.width) {
            frameSize.width = screenSize.width;
        }
        frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    }

    public static void centerWindow(JDialog dialog) {
        // Center the window
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension dialogSize = dialog.getSize();
        if (dialogSize.height > screenSize.height) {
            dialogSize.height = screenSize.height;
        }
        if (dialogSize.width > screenSize.width) {
            dialogSize.width = screenSize.width;
        }
        dialog.setLocation((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2);
    }
}

Related

  1. centerDialogInContainer(JDialog dialog, Container frame)
  2. centerDialogInWindow(JDialog dialog, Window win)
  3. centerOn(JDialog dialog, Component other)
  4. centerOnComponent(JDialog dialog, Component comp)
  5. centerOnScreen(JDialog jdialog)
  6. centerWindow(JDialog dialog)
  7. centrarVentana(JDialog pDialog)
  8. getCentralDialogLocation(Component parent, JDialog dialog)
  9. getCentredDialogBounds(JDialog dialog, Component parent, int defaultWidth, int defaultHeight)