set Frame Center - Java Swing

Java examples for Swing:JFrame

Description

set Frame 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 screen = toolkit.getScreenSize();

        int x = screen.width - jf.getWidth() >> 1;
        int y = screen.height - jf.getHeight() >> 1 - 32;
        jf.setLocation(x, y);//w  w w . j a  va  2 s.com
    }
}

Related Tutorials