Java JFrame Center centerFrameOnScreen(JFrame frame)

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

Description

Centers a JFrame on screen.

License

Open Source License

Declaration

public static void centerFrameOnScreen(JFrame frame) 

Method Source Code


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

import java.awt.*;

import javax.swing.*;

public class Main {
    /**//from www  . j  av  a  2 s . com
     * Centers a {@link JFrame} on screen.
     */
    public static void centerFrameOnScreen(JFrame frame) {
        final Dimension position = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation((position.width - frame.getWidth()) / 2, (position.height - frame.getHeight()) / 2);
    }
}

Related

  1. centerFrame(JFrame frame)
  2. centerFrame(JFrame frame)
  3. centerFrame(JFrame frame, boolean isPopup)
  4. centerFrame(Window owner)
  5. centerFrameOnMainDisplay(final JFrame frame)
  6. centerFrameOnScreen(JFrame frame)
  7. centerFrameTo(final JFrame frameToCenter, final Dimension orientDim)
  8. centerJFrame(JFrame frame)
  9. centerOnFrame(JDialog dialog, JFrame frame)