code: private Rectangle findLargestVisibleRectFor(final Rectangle overlayRect)
      {
          Rectangle visibleRect = null;
          int curxoffset = 0;
          int curyoffset = 0;
          if (overlayTarget == null)
          {
              return null;
          }
  
          JComponent comp = overlayTarget;
          do
          {
  
              visibleRect = comp.getVisibleRect();
              visibleRect.x -= curxoffset;
              visibleRect.y -= curyoffset;
              if (visibleRect.contains(overlayRect))
              {
                  return visibleRect;
              }
              curxoffset += comp.getX();
              curyoffset += comp.getY();
  
              comp = comp.getParent() instanceof JComponent ? (JComponent) comp.getParent() : null;
          }
          while (comp != null && !(comp instanceof JViewport) && !(comp instanceof JScrollPane));
  
  
          return visibleRect;
      }
docs: Searches up the component hierarchy to find the largest possible visible
  rect that can enclose the entire rectangle.
  
  @param overlayRect rectangle whose largest enclosing visible rect to find
  @return largest enclosing visible rect for the specified rectangle