Java JComponent Container getOutermostRootPane(Component c)

Here you can find the source of getOutermostRootPane(Component c)

Description

If c is a JRootPane descendant return its outermost JRootPane ancestor.

License

Open Source License

Parameter

Parameter Description
c the component.

Return

the outermost JRootPane for Component c or null .

Declaration

public static JRootPane getOutermostRootPane(Component c) 

Method Source Code

//package com.java2s;
import javax.swing.*;

import java.awt.*;

public class Main {
    /**/*from w ww. ja  v a  2s .c  om*/
     * If c is a JRootPane descendant return its outermost JRootPane ancestor. If c is a RootPaneContainer then return
     * its JRootPane.
     *
     * @param c the component.
     * @return the outermost JRootPane for Component c or {@code null}.
     */
    public static JRootPane getOutermostRootPane(Component c) {
        if (c instanceof RootPaneContainer && c.getParent() == null) {
            return ((RootPaneContainer) c).getRootPane();
        }
        JRootPane lastRootPane;
        for (; c != null; c = SwingUtilities.getRootPane(c)) {
            if (c instanceof JRootPane) {
                lastRootPane = (JRootPane) c;
                if (c.getParent().getParent() == null) {
                    return lastRootPane;
                }
                if (c.getParent() instanceof JDialog
                        || c.getParent() instanceof JWindow
                        || c.getParent() instanceof JFrame
                        || c.getParent() instanceof JApplet) {
                    return lastRootPane;
                }
                c = c.getParent().getParent();
            }
        }
        return null;
    }
}

Related

  1. getInterior(JComponent comp)
  2. getLocalInsetBounds(JComponent component)
  3. getMandatoryPanel(JComponent c)
  4. getMaxVisibleY(JComponent comp)
  5. getModelObject(JComponent c)
  6. getOutermostRootPane(Component c)
  7. getPanelFor(JComponent comp1, JComponent comp2)
  8. getPanelFor(JComponent comp1, JComponent comp2)
  9. getParent(JComponent parent, final int... path)