Java tutorial
//package com.java2s; //License from project: LGPL import java.awt.Component; public class Main { public static <T extends Component> T findParentComponentOfType(Component component, Class<T> type) { do { component = component.getParent(); if (component != null && type.isAssignableFrom(component.getClass())) { return (T) component; } } while (component != null); return null; } }