Java tutorial
//package com.java2s; //License from project: Open Source License import java.awt.Component; import java.awt.Dialog; import java.awt.Frame; import java.awt.Window; import javax.swing.SwingUtilities; public class Main { static boolean ALWAYS_USE_FRAME = true; static Window getDialog(Component parentComponent, String title, boolean modal) { if (ALWAYS_USE_FRAME) return new Frame(title); Window dialog; Window window = getComponentWindow(parentComponent); if (window instanceof Frame) { dialog = new Dialog((Frame) window, title, modal); } else { dialog = new Dialog((Dialog) window, title, modal); } return dialog; } static Window getComponentWindow(Component component) { if (component instanceof Window) { return (Window) component; } return SwingUtilities.getWindowAncestor(component); } }