Mega Code Archive

 
Categories / Java / Swing JFC
 

Gets the root pane of the given component

//package com.javadocking.util; import java.awt.Component; import java.awt.Container; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Point; import java.awt.Rectangle; import java.awt.Window; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLayeredPane; import javax.swing.JRootPane; import javax.swing.JWindow; import javax.swing.SwingUtilities; /**  * This class contains a collection of static utility methods for Swing.  *   * @author Heidi Rakels.  */ public class SwingUtil {      /**    * Gets the root pane of the given component.    *     * @param   component    The component whose root pane is retrieved.    * @return           The root pane of the component.    */   public static JRootPane getRootPane(Component component)   {          if (component instanceof JRootPane) {       return (JRootPane)component;     }     if (component.getParent() != null) {       return getRootPane(component.getParent());     }          // Get the window of the component.     Window window = SwingUtilities.windowForComponent(component);     return getRootPane(window);          } }