Java JFrame Center centerFrame(JFrame frame)

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

Description

center Frame

License

Apache License

Declaration

public static void centerFrame(JFrame frame) 

Method Source Code

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

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

public class Main {
    public static void centerFrame(JFrame frame) {
        // Get the size of the screen
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

        // Determine the new location of the window
        int w = frame.getSize().width;
        int h = frame.getSize().height;
        int x = (dim.width - w) / 2;
        int y = (dim.height - h) / 2;

        // Move the window
        frame.setLocation(x, y);/*w w  w.ja  v  a  2 s.co  m*/
    }
}

Related

  1. centerFrame(JFrame frame)
  2. centerFrame(JFrame frame)
  3. centerFrame(JFrame frame)
  4. centerFrame(JFrame frame)
  5. centerFrame(JFrame frame)
  6. centerFrame(JFrame frame)
  7. centerFrame(JFrame frame, boolean isPopup)
  8. centerFrame(Window owner)
  9. centerFrameOnMainDisplay(final JFrame frame)