Here you can find the source of rootPaneForComponent(Component comp)
public static JRootPane rootPaneForComponent(Component comp)
//package com.java2s; //License from project: Apache License import java.awt.Component; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JRootPane; import javax.swing.JWindow; public class Main { public static JRootPane rootPaneForComponent(Component comp) { for (Component p = comp; p != null; p = p.getParent()) { if (p instanceof JRootPane) { return (JRootPane) p; }// w w w .j a v a 2s . c o m if (comp instanceof JFrame) { return ((JFrame) comp).getRootPane(); } if (comp instanceof JDialog) { return ((JDialog) comp).getRootPane(); } if (comp instanceof JWindow) { return ((JWindow) comp).getRootPane(); } } return null; } }