Java tutorial
//package com.java2s; //License from project: Open Source License import java.awt.Window; import javax.swing.JDialog; public class Main { public static JDialog getOnlyVisibleDialog(Window owner) { JDialog d = null; for (Window w : Window.getWindows()) { // System.out.println("found " + w + " " + w.getOwner()); if (w instanceof JDialog && w.isShowing() && ((JDialog) w).getOwner() == owner) { if (d != null) throw new IllegalStateException("num dialogs > 1"); d = (JDialog) w; } } return d; } }