Display JFrame In Center - Java Swing

Java examples for Swing:JFrame

Description

Display JFrame In Center

Demo Code


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

public class Main {
    public static void DisplayInCenter(JFrame frame) {

        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

        Dimension frameSize = frame.getSize();

        frame.setLocation((screenSize.width - frameSize.width) / 2,
                (screenSize.height - frameSize.height) / 2);

    }/*from  w  w  w .  j  av  a2  s . com*/
}

Related Tutorials