Java tutorial
//package com.java2s; import java.awt.Component; import java.awt.Container; import java.awt.Window; public class Main { public static Window getOwnerWindow(Component component) { if (component instanceof Window) { return (Window) component; } Container parent = component.getParent(); while (!(parent instanceof Window)) { parent = parent.getParent(); if (parent == null) { throw new IllegalArgumentException("Component has no root window."); } } return (Window) parent; } }