Java examples for java.awt:Component
get Component Top level Ancestor
//package com.java2s; import javax.swing.*; import java.applet.Applet; import java.awt.*; public class Main { public static Component getToplevelAncestor(Component component) { for (Component p = component; p != null; p = p.getParent()) { if (p instanceof Window || p instanceof Applet) { return p; } else if (p instanceof JPopupMenu) { return getToplevelAncestor(((JPopupMenu) p).getInvoker()); }/*from w w w .ja va2s. c o m*/ } return null; } }