set JWindow JFrame Center - Java Swing

Java examples for Swing:JWindow

Description

set JWindow JFrame Center

Demo Code


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

import javax.swing.JFrame;

import javax.swing.JWindow;

public class Main {

    public static void setCenter(JWindow win) {
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        win.setLocation((d.width - win.getWidth()) / 2,
                (d.height - win.getHeight()) / 2);
    }/*  w  w w . j a  v  a 2  s.c o  m*/

    public static void setCenter(JFrame frame) {
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation((d.width - frame.getWidth()) / 2,
                (d.height - frame.getHeight()) / 2);
    }
}

Related Tutorials