code: @Override
      protected JScrollPane getEnclosingScrollPane() {
          Container p = SwingUtilities.getUnwrappedParent(this);
          if (p instanceof JViewport) {
              Container gp = p.getParent();
              if (gp instanceof JScrollPane) {
                  JScrollPane scrollPane = (JScrollPane) gp;
                  // Make certain we are the viewPort's view and not, for
                  // example, the rowHeaderView of the scrollPane -
                  // an implementor of fixed columns might do this.
                  JViewport viewport = scrollPane.getViewport();
                  if (viewport == null || SwingUtilities.getUnwrappedView(viewport) != this) {
                      return null;
                  }
                  return scrollPane;
              }
          }
          return null;
      }
docs: the methods SwingUtilities#getUnwrappedParent(Component) and SwingUtilities#getUnwrappedView(JViewport) respectively.