Java JFrame Center placeInCenter(JFrame frame)

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

Description

place In Center

License

Open Source License

Declaration

public static void placeInCenter(JFrame frame) 

Method Source Code

//package com.java2s;
/*/* w w  w .j  ava  2  s  .co  m*/
 * MiscUtil.java
 * miscellaneous utilities
 * Copyright (C) 2006 by Institute for Systems Biology,
 * Seattle, Washington, USA.  All rights reserved.
 *
 * This source code is distributed under the GNU Lesser
 * General Public License, the text of which is available at:
 *   http://www.gnu.org/copyleft/lesser.html
 */

import java.awt.GraphicsConfiguration;

import javax.swing.JFrame;

public class Main {
    public static void placeInCenter(JFrame frame) {
        GraphicsConfiguration gc = frame.getGraphicsConfiguration();
        int screenHeight = (int) gc.getBounds().getHeight();
        int screenWidth = (int) gc.getBounds().getWidth();
        int windowWidth = frame.getWidth();
        int windowHeight = frame.getHeight();
        frame.setLocation((screenWidth - windowWidth) / 2, (screenHeight - windowHeight) / 2);
    }
}

Related

  1. centerWindowOnParent(Window w, JFrame parent)
  2. centerWithinDesktop(JInternalFrame frame)
  3. createCenteredJFrame(String title, int width, int height, boolean autoclose)
  4. getCenteringFrame()
  5. getCenterOfTheWindow(JFrame frame)
  6. posiToScreenCenter(JFrame frame)
  7. putWindowInCenter(JFrame window)
  8. SET_FRAME_CENTER(JFrame frame)
  9. sizeAndCenterFrame(JFrame aFrame, int aWidth, int aHeight)