Java JFrame Center centerOnFrame(JDialog dialog, JFrame frame)

Here you can find the source of centerOnFrame(JDialog dialog, JFrame frame)

Description

center On Frame

License

Apache License

Declaration

public static void centerOnFrame(JDialog dialog, JFrame frame) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import javax.swing.*;

import java.awt.*;

public class Main {
    public static void centerOnFrame(JDialog dialog, JFrame frame) {
        Point frameLoc = frame.getLocation();
        Dimension frameSize = frame.getSize();
        Dimension dialogSize = dialog.getSize();
        int dialogX = frameLoc.x + (frameSize.width - dialogSize.width) / 2;
        int dialogY = frameLoc.y + (frameSize.height - dialogSize.height) / 2;
        dialog.setLocation(dialogX, dialogY);
    }/*  w w  w.  j a  v a  2s. co m*/

    public static void centerOnFrame(JFrame dialog, JFrame frame) {
        Point frameLoc = frame.getLocation();
        Dimension frameSize = frame.getSize();
        Dimension dialogSize = dialog.getSize();
        int dialogX = frameLoc.x + (frameSize.width - dialogSize.width) / 2;
        int dialogY = frameLoc.y + (frameSize.height - dialogSize.height) / 2;
        dialog.setLocation(dialogX, dialogY);
    }

    public static void centerOnFrame(Frame dialog, JFrame frame) {
        Point frameLoc = frame.getLocation();
        Dimension frameSize = frame.getSize();
        Dimension dialogSize = dialog.getSize();
        int dialogX = frameLoc.x + (frameSize.width - dialogSize.width) / 2;
        int dialogY = frameLoc.y + (frameSize.height - dialogSize.height) / 2;
        dialog.setLocation(dialogX, dialogY);
    }
}

Related

  1. centerFrameOnMainDisplay(final JFrame frame)
  2. centerFrameOnScreen(JFrame frame)
  3. centerFrameOnScreen(JFrame frame)
  4. centerFrameTo(final JFrame frameToCenter, final Dimension orientDim)
  5. centerJFrame(JFrame frame)
  6. centerOnFrame(JFrame frame, Component comp)
  7. centerOnParent(JDialog child, JFrame parent)
  8. centerOnScreen(JFrame frame, int screenID)
  9. centerPoint(int width, int height, JFrame frame)