set Frame To Screen Center - Java Swing

Java examples for Swing:JFrame

Description

set Frame To Screen Center

Demo Code


//package com.java2s;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.Window;

public class Main {
    public static void setFrameToScreenCenter(Window frame) {
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation(screen.width / 2 - frame.getWidth() / 2,
                screen.height / 2 - frame.getHeight() / 2);
    }// w  ww.  jav  a 2 s  . co  m
}

Related Tutorials