Java JComponent Container findRootPaneContainer(Component root)

Here you can find the source of findRootPaneContainer(Component root)

Description

Finds the nearest RootPaneContainer of the provided Component.

License

Open Source License

Parameter

Parameter Description
root the Component

Return

a RootPaneContainer for the provided component

Declaration

public static RootPaneContainer findRootPaneContainer(Component root) 

Method Source Code


//package com.java2s;
/*// www.  j av a 2 s .  c  o m
 * Copyright (C) 2009 Illya Yalovyy
 * Use is subject to license terms.
 */

import java.awt.Component;

import javax.swing.JPopupMenu;
import javax.swing.RootPaneContainer;

public class Main {
    /**
     * Finds the nearest RootPaneContainer of the provided Component. 
     * Primarily, if a JPopupMenu (such as used by JMenus when they are visible) has no parent,
     * the search continues with the JPopupMenu's invoker instead. Fixes BSAF-77
     * 
     * @return a RootPaneContainer for the provided component
     * @param root the Component
     */
    public static RootPaneContainer findRootPaneContainer(Component root) {
        while (root != null) {
            if (root instanceof RootPaneContainer) {
                return (RootPaneContainer) root;
            } else if (root instanceof JPopupMenu && root.getParent() == null) {
                root = ((JPopupMenu) root).getInvoker();
            } else {
                root = root.getParent();
            }
        }
        return null;
    }
}

Related

  1. centerOnComponet(Window target, JComponent parent)
  2. checkComponents(final Component _rootComponent, final String _print, final int _currentColumn, final int _currentRow)
  3. findMainRootPane(Component component)
  4. findRootPane(Component component)
  5. findRootPaneContainer(Component c)
  6. findRootPaneContainer(final Component source)
  7. getActiveRectangle(JComponent c)
  8. getAllJComponents(Container container, Collection collection)
  9. getAncestorOfType(JComponent component, Class type)