Java tutorial
//package com.java2s; import java.awt.Component; import java.awt.Container; import java.awt.Window; public class Main { /** * Finds the Window containing this component, or null if none found. * @param component the component to search * @return the Window containing the component */ public static Window findContainingWindow(Component component) { Container container = component.getParent(); while (container != null && !(container instanceof Window)) { container = container.getParent(); } return (Window) container; } }