public static Component findParent ( final Component childComponent , final Class < ? extends Component > parentClass , final boolean byClassname ) { Component parent = childComponent . getParent ( ) ; while ( parent != null ) { if ( parent . getClass ( ) . equals ( parentClass ) ) { break ; } parent = parent . getParent ( ) ; } if ( ( parent == null ) && byClassname ) { return findParentByClassname ( childComponent , parentClass ) ; } return parent ; }
Finds the first parent of the given childComponent from the given parentClass and a flag if the search shell be continued with the class name if the search with the given parentClass returns null .