Java JFrame Center centerDialog(JDialog dialog, JFrame parent)

Here you can find the source of centerDialog(JDialog dialog, JFrame parent)

Description

center Dialog

License

Open Source License

Declaration

static public void centerDialog(JDialog dialog, JFrame parent) 

Method Source Code


//package com.java2s;
// it under the terms of the GNU General Public License as published by

import javax.swing.*;
import java.awt.*;

public class Main {
    static public void centerDialog(JDialog dialog, JFrame parent) {
        Point p = parent.getLocationOnScreen();
        p.x += ((parent.getWidth() - dialog.getWidth()) / 2);
        p.y += ((parent.getHeight() - dialog.getHeight()) / 2);
        if (p.y <= 0)
            p.y = 20;//from  w w w  .j  av  a 2  s .c  o m
        if (p.x <= 0)
            p.x = 20;
        dialog.setLocation(p);
    }

    static public void centerDialog(JDialog dialog, JDialog parent) {
        Point p = parent.getLocationOnScreen();
        p.x += ((parent.getWidth() - dialog.getWidth()) / 2);
        p.y += ((parent.getHeight() - dialog.getHeight()) / 2);
        if (p.y <= 0)
            p.y = 20;
        if (p.x <= 0)
            p.x = 20;
        dialog.setLocation(p);
    }
}

Related

  1. center(JFrame parent, JInternalFrame dialog)
  2. centerAndSizeFrame(JFrame frame)
  3. centerBigFrame(JFrame frame, int maxWidth, int maxHeight, double scaling, int minHeight)
  4. centerDialog(final JFrame frame, JDialog dialog)
  5. centerDialog(JDialog dialog, JFrame frame)
  6. centerDialogIntoFrame(java.awt.Component p_CompToBePositioned, javax.swing.JFrame p_MainFrame)
  7. centerDialogOnFrame(JFrame parentFrame, JDialog dialog)
  8. centerFrame(final JFrame target)
  9. centerFrame(JFrame frame)