title: Java JScrollPane Remove Components Without Changing Viewport
body: <p>When there are more than 50 components in my JScrollPane, every time the user decides to go to the next page, the first 10 components in the JScrollPane are cleared.</p>
  
  <p>This functionality works fine and is desirable, but when the components are removed, the viewport/scroll is changed. The view of the scrollpane jumps back each time the components are cleared.</p>
  
  <p>What I'd like is to keep the viewport at exactly the same place, while removing the first components from the JScrollPane.</p>
  
  <p>At the moment I have a workaround, but it's not elegant, and although it finds where the user last was, it's choppy, and jumps the scrollpane which doesn't look right:</p>
  
  <pre><code>if (middlePanel.getComponents().length &gt; 50)
  {
      Component currentScroll = scrollPane.getViewport().getView();
      for (int counter = 0; counter &lt; memeAnchors.size(); counter++)
      {
          middlePanel.remove(counter);
      }
      scrollPane.setViewportView(currentScroll);
      scrollPane.getVerticalScrollBar().setValue(scrollPane.getVerticalScrollBar().getValue() - 800);
  }
  </code></pre>
  
  <p>Is what I want to do even possible?</p>
  
  <p>Thanks in advance everyone,</p>