Java JFrame Center SET_FRAME_CENTER(JFrame frame)

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

Description

SEFRAMCENTER

License

Open Source License

Declaration

public static void SET_FRAME_CENTER(JFrame frame) 

Method Source Code


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

import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JFrame;

public class Main {
    public static void SET_FRAME_CENTER(JFrame frame) {
        Dimension screenSize = new Dimension(Toolkit.getDefaultToolkit().getScreenSize());
        Dimension windowSize = new Dimension(frame.getPreferredSize());
        int wdwLeft = screenSize.width / 2 - windowSize.width / 2;
        int wdwTop = screenSize.height / 2 - windowSize.height / 2;
        frame.pack();/*  w ww  .j a v  a2  s  .  c om*/
        frame.setLocation(wdwLeft, wdwTop);
    }
}

Related

  1. getCenteringFrame()
  2. getCenterOfTheWindow(JFrame frame)
  3. placeInCenter(JFrame frame)
  4. posiToScreenCenter(JFrame frame)
  5. putWindowInCenter(JFrame window)
  6. sizeAndCenterFrame(JFrame aFrame, int aWidth, int aHeight)