public static Component getRoot ( Component comp , Rectangle rect ) { for ( Component c = comp ; c != null ; c = c . getParent ( ) ) { if ( ! c . isVisible ( ) || ! c . isDisplayable ( ) ) { return null ; } if ( c instanceof Window || c instanceof Applet ) { return c ; } rect . x += c . getX ( ) ; rect . y += c . getY ( ) ; } return null ; }
Returns the root component for the supplied component or null if it is not part of a rooted hierarchy or if any parent along the way is found to be hidden or without a peer . Along the way it adjusts the supplied component - relative rectangle to be relative to the returned root component .