show Center Swing JDialog - Java Swing

Java examples for Swing:JDialog

Description

show Center Swing JDialog

Demo Code


//package com.java2s;

import java.awt.Dimension;

import java.awt.Toolkit;

import javax.swing.JDialog;

public class Main {
    public static void showCenterDialog(JDialog dialog) {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension screen = toolkit.getScreenSize();
        dialog.setBounds((screen.width - dialog.getWidth()) / 2,
                (screen.height - dialog.getHeight()) / 2,
                dialog.getWidth(), dialog.getHeight());
        dialog.setVisible(true);//  ww w.j ava  2s . c  om
    }
}

Related Tutorials