Java tutorial
//package com.java2s; import java.awt.Component; import java.awt.Container; public class Main { public static Container getTopContainer(Component component, Class<Component> lookupClass) { Container parent = component.getParent(); if (parent.getClass().equals(lookupClass)) { return parent; } else { return getTopContainer(parent, lookupClass); } } }