Java tutorial
//package com.java2s; import java.awt.*; public class Main { /** * Gets the top parent Window of the given component. There is a limit to how far up the parent stack it'll go. * * @param <T> * @param jComponent * @return */ public static <T extends Window> T getParentWindow(Component jComponent) { Container parent = jComponent.getParent(); int i = 0; int limit = 100; while (true) { parent = parent.getParent(); if (parent instanceof Window) { return (T) parent; } i++; if (i > limit) { return null; //Just to prevent an infinite loop... } } } }