SwingXUtilities { public static boolean isDescendingFrom(Component focusOwner, Component parent) { while (focusOwner != null) { if (focusOwner instanceof JPopupMenu) { focusOwner = ((JPopupMenu) focusOwner).getInvoker(); if (focusOwner == null) { return false; } } if (focusOwner == parent) { return true; } focusOwner = focusOwner.getParent(); } return false; } private  SwingXUtilities(); static void updateMnemonicBinding(JComponent c, String pressed); static void updateMnemonicBinding(JComponent c, String pressed, String released); static void setComponentTreeEnabled(Component c, boolean enabled); static void setComponentTreeLocale(Component c, Locale locale); static void setComponentTreeBackground(Component c, Color color); static void setComponentTreeForeground(Component c, Color color); static void setComponentTreeFont(Component c, Font font); static void setHtmlFont(HTMLDocument doc, Font font); static void updateAllComponentTreeUIs(); static void updateAllComponentTreeUIs(Window window); static FutureTask<T> invokeLater(Callable<T> callable); static T invokeAndWait(Callable<T> callable); @SuppressWarnings("unchecked") static T getAncestor(Class<T> clazz, Component c); static boolean isDescendingFrom(Component focusOwner, Component parent); static boolean isUIInstallable(Object property); static void setLeadAnchorWithoutSelection(
            ListSelectionModel selectionModel, int lead, int anchor); static boolean shouldIgnore(MouseEvent mouseEvent,
            JComponent component); static int loc2IndexFileList(JList list, Point point); static void adjustFocus(JComponent component); static int convertModifiersToDropAction(int modifiers,
            int sourcActions);  }
@Test public void testDescendingNull() { assertFalse("both nulls are not descending", SwingXUtilities.isDescendingFrom(null, null)); assertFalse("null comp is not descending", SwingXUtilities.isDescendingFrom(null, new JScrollPane())); assertFalse("comp is not descending null parent", SwingXUtilities.isDescendingFrom(new JLabel(), null)); }
@Test public void testDescendingSame() { JComponent comp = new JLabel(); assertTrue("same component must be interpreted as descending", SwingXUtilities.isDescendingFrom(comp, comp)); }