Java tutorial
//package com.java2s; //License from project: Apache License import java.awt.Component; import java.awt.Window; public class Main { static public Window getParentContainer(Component component) { if (component instanceof Window) { return (Window) component; } while (component.getParent() != null) { component = component.getParent(); if (component instanceof Window) { return (Window) component; } } if (component instanceof Window) { return (Window) component; } else { return null; } } }