title: Resize JPanel within JScrollPane - never smaller than viewport
body: <p>I've created a JPanel and JScrollPane like so:</p>
  
  <pre><code>JPanel panel = new JPanel();
  panel.setPreferredSize(5000, 5000);
  JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  scrollPanel.getViewport().setBackground(Color.GRAY); //panel is white
  </code></pre>
  
  <p>I will be using event handlers to dynamically resize the panel. The problem is, sometimes the panel is smaller than the viewport. I'd set the panel's size like this:</p>
  
  <pre><code>panel.setPreferredSize(10, 10); //Just an example
  </code></pre>
  
  <p>but the panel will never be smaller than the viewport. I tried using</p>
  
  <pre><code>panel.setSize(10, 10);
  </code></pre>
  
  <p>and i saw a gray flicker (the viewport's background showing through), which indicated that the panel <em>was</em> being sized to what i wanted it to be, but then grew to the viewport's size. How can i stop this?</p>