List of usage examples for java.awt Container getParent
public Container getParent()
From source file:Main.java
/** * Gets the top parent Window of the given component. There is a limit to how far up the parent stack it'll go. * * @param <T>//from www .j a va 2s . c om * @param jComponent * @return */ public static <T extends Window> T getParentWindow(Component jComponent) { Container parent = jComponent.getParent(); int i = 0; int limit = 100; while (true) { parent = parent.getParent(); if (parent instanceof Window) { return (T) parent; } i++; if (i > limit) { return null; //Just to prevent an infinite loop... } } }
From source file:Main.java
public static JFrame getFrame(Container target) { if (target instanceof JFrame) { return (JFrame) target; }/*from w w w.j ava2 s .c om*/ return getFrame(target.getParent()); }
From source file:Main.java
public static JInternalFrame getInternalFrameForComponent(JComponent c) { java.awt.Container p = c; do {//from w w w . j a v a 2 s . c om if (p instanceof JInternalFrame) { return (JInternalFrame) p; } p = p.getParent(); } while (p != null); return null; }
From source file:Main.java
static public <T extends Container> T findAncestorOfType(Container acomp, Class<T> type) { Container parent = acomp; while (parent != null) { if (type.isInstance(parent)) return type.cast(parent); parent = parent.getParent(); }//w w w . ja v a2s . co m return null; }
From source file:Main.java
/** * Convenience method for searching above the given component in the component * hierarchy and returns the first object of the given type it finds, or * <code>null</code> if no such parent was found. * <p>/*from w ww . j av a 2 s. co m*/ * The reason this method exists is for tidyness of the calling code, as no * longer a explicit cast is needed. * * @param aType * the type of the parent to find, cannot be <code>null</code>; * @param aComponent * the component to search in the hierarchy, cannot be * <code>null</code>. * @return the requested ancestor, or <code>null</code> if not found. * @see SwingUtilities#getAncestorOfClass(Class, Component) */ @SuppressWarnings("unchecked") public static <T> T getAncestorOfClass(final Class<T> aType, final Component aComponent) { if ((aComponent == null) || (aType == null)) { return null; } Container parent = aComponent.getParent(); while ((parent != null) && !(aType.isInstance(parent))) { parent = parent.getParent(); } return (T) parent; }
From source file:Main.java
public static Frame getFrameOwner(Component c) { Container parent = c.getParent(); while (parent != null && !(parent instanceof Frame)) { System.out.println("PARENT " + parent); parent = parent.getParent(); }//from ww w. j a v a 2 s .c o m if (parent != null) { return (Frame) parent; } else { return null; } }
From source file:Main.java
public static Frame findParentFrame(Component component) { if (component == null) { throw new NullPointerException("component == null"); }/*from w w w.j a v a2 s. c o m*/ Container parent = component.getParent(); while (parent != null) { if ((parent instanceof Frame)) { return (Frame) parent; } parent = parent.getParent(); } return null; }
From source file:Main.java
public static boolean isVisible(Container container) { Container currentComponent = container; while (currentComponent != null) { if (!currentComponent.isVisible()) { return false; }/* w w w .jav a2s. c o m*/ currentComponent = currentComponent.getParent(); } return true; }
From source file:Main.java
public static Container getRootContainer(Component c) { if (c == null) { return null; }/*from w w w .j a v a2 s . c om*/ Container parent = c.getParent(); while ((parent != null) && !(parent instanceof JPopupMenu) && !(parent instanceof JInternalFrame) && !(parent instanceof Window) && (parent.getParent() != null)) { parent = parent.getParent(); } return parent; }
From source file:Main.java
/** * Tests whether the component passed in parameter is used as an editor. * * @param comp/* w w w .ja v a2s .c o m*/ * the component to test. * @return true if the component is currently used as an editor. */ public static boolean isUsedAsEditor(Component comp) { boolean usedAsEditor = false; Container parent = comp.getParent(); while (parent != null && !usedAsEditor) { if (parent instanceof JTable) { usedAsEditor = true; } parent = parent.getParent(); } return usedAsEditor; }