Java JFrame Center center(JFrame frame)

Here you can find the source of center(JFrame frame)

Description

Center JFrame.

License

Open Source License

Declaration

public static void center(JFrame frame) 

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  www  . ja v a  2 s.com
     * 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. alignCenter(JInternalFrame internalFrame)
  2. center(JFrame frame)
  3. center(JFrame parent, JInternalFrame dialog)
  4. centerAndSizeFrame(JFrame frame)
  5. centerBigFrame(JFrame frame, int maxWidth, int maxHeight, double scaling, int minHeight)