break; } }
  private Component findOverlapFreeParent(Rectangle clip)  {    Rectangle currentClip = clip;    Component found = this;    Container parent = this;     while (parent != null && !(parent instanceof Window))      {        Container newParent = parent.getParent();        if (newParent == null)          break;        // If the parent is optimizedDrawingEnabled, then its children are        // tiled and cannot have an overlapping child. Go directly to next        // parent.        if (newParent instanceof JComponent            && ((JComponent) newParent).isOptimizedDrawingEnabled())          {            parent = newParent;            continue;          }        // First we must check if the new parent itself somehow clips the        // target rectangle. This can happen in JViewports.        Rectangle parRect = new Rectangle(0, 0, newParent.getWidth(),                                          newParent.getHeight());        Rectangle target = SwingUtilities.convertRectangle(found,                                                           currentClip,                                                           newParent);        if (target.contains(parRect) || target.intersects(parRect))          {            found = newParent;            currentClip = target;            parent = newParent;            continue;          }        // Otherwise we must check if one of the children of this parent        // overlaps with the current component.        Component[] children = newParent.getComponents();        // This flag is used to skip components that are 'below' the component        // in question.        boolean skip = true;        for (int i = children.length - 1; i >= 0; i--)          {            if (children[i] == parent)              skip = false;            if (skip)              continue;            Component c = children[i];            Rectangle compBounds = c.getBounds();            // If the component completely overlaps the clip in question, we            // don't need to repaint. Return null.            if (compBounds.contains(target))              return null;            if (compBounds.intersects(target))              {                // We found a parent whose children overlap with our current                // component. Make this the current component.                found = newParent;                currentClip = target;                break;              }          }        parent = newParent;      }    return found;  }