Here you can find the source of findRootPaneContainer(Component root)
Parameter | Description |
---|---|
root | the Component |
public static RootPaneContainer findRootPaneContainer(Component root)
//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; } }