Java JComponent Container getAncestorOfType(JComponent component, Class type)

Here you can find the source of getAncestorOfType(JComponent component, Class type)

Description

get Ancestor Of Type

License

Open Source License

Declaration

static public <T> T getAncestorOfType(JComponent component, Class<T> type) 

Method Source Code

//package com.java2s;
/***************************************************************************
 * Copyright 2001-2007 The eXo Platform SARL         All rights reserved.  *
 * Please look at license.txt in info directory for more license detail.   *
 **************************************************************************/

import java.awt.Container;
import javax.swing.JComponent;

public class Main {
    static public <T> T getAncestorOfType(JComponent component, Class<T> type) {
        Container ancestor = component.getParent();
        while (ancestor != null) {
            System.out.println("Check  parent : " + ancestor);
            if (type.isInstance(ancestor))
                return (T) ancestor;
            ancestor = ancestor.getParent();
        }/*from   w  w w . jav  a  2  s  . co  m*/
        return null;
    }
}

Related

  1. findRootPaneContainer(Component c)
  2. findRootPaneContainer(Component root)
  3. findRootPaneContainer(final Component source)
  4. getActiveRectangle(JComponent c)
  5. getAllJComponents(Container container, Collection collection)
  6. getAncestorsOfClass(JComponent start, Class theClass)
  7. getBooleanClientProperty(JComponent c, Object property)
  8. getChildJComponents(Container container)
  9. getClipboard(JComponent c)