set JFrame Center - Java Swing

Java examples for Swing:JFrame

Description

set JFrame Center

Demo Code


//package com.java2s;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;

public class Main {

    public static void setFrameCenter(JFrame jf) {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension din = toolkit.getScreenSize();
        int x = (din.width - jf.getWidth()) / 2;
        int y = (din.height - jf.getHeight()) / 2 - 32;
        jf.setLocation(x, y);/*from  w w w . j a  va  2  s . co m*/

    }
}

Related Tutorials