code: private void updateDecorationPainterClippedBounds(JLayeredPane layeredPane, Point relativeLocationToOwner) {
          if (layeredPane == null) {
              decorationPainter.setClipBounds(null);
          } else {
              JComponent clippingComponent = getEffectiveClippingAncestor();
              if (clippingComponent == null) {
                  LOGGER.error("No decoration clipping component can be found for decorated component: " +
                          decoratedComponent);
                  decorationPainter.setClipBounds(null);
              } else if (clippingComponent.isShowing()) {
                  Rectangle ownerBoundsInParent = decoratedComponent.getBounds();
                  Rectangle decorationBoundsInParent = new Rectangle(ownerBoundsInParent.x + relativeLocationToOwner.x,
                          ownerBoundsInParent.y + relativeLocationToOwner.y, getWidth(), getHeight());
                  Rectangle decorationBoundsInAncestor = SwingUtilities.convertRectangle(decoratedComponent.getParent()
                          , decorationBoundsInParent, clippingComponent);
                  Rectangle decorationVisibleBoundsInAncestor;
                  Rectangle ancestorVisibleRect = clippingComponent.getVisibleRect();
                  decorationVisibleBoundsInAncestor = ancestorVisibleRect.intersection(decorationBoundsInAncestor);
  
                  if ((decorationVisibleBoundsInAncestor.width == 0) || (decorationVisibleBoundsInAncestor.height == 0)) {
                      // No bounds, no painting
                      decorationPainter.setClipBounds(null);
                  } else {
                      Rectangle decorationVisibleBoundsInLayeredPane = SwingUtilities.convertRectangle
                              (clippingComponent, decorationVisibleBoundsInAncestor, layeredPane);
  
                      // Clip graphics context
                      Rectangle clipBounds = SwingUtilities.convertRectangle(decorationPainter.getParent(),
                              decorationVisibleBoundsInLayeredPane, decorationPainter);
                      decorationPainter.setClipBounds(clipBounds);
                  }
              } else {
                  // This could happen for example when a dialog is closed, so no need to log anything
                  decorationPainter.setClipBounds(null);
              }
          }
      }
docs: Calculates and updates the clipped bounds of the decoration painter in layered pane coordinates.
  
  @param layeredPane             Layered pane containing the decoration painter.
  @param relativeLocationToOwner Location of the decoration painter relatively to the decorated component.