title: add scroll to JPanel
body: <p>I have a problem adding scrollbar to my JPanel. This is my code but it isn't working! I need help!</p>
  
  <hr>
  
  <pre><code>public class DocumentView extends JPanel implements EventListener,MouseListener{
  
      public String name;
      private Document document;
      private Dimension dim;
      public DocumentView dv;
  
      JScrollPane scrollPane = new JScrollPane(dv,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
          JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
  
  
      public boolean selected = false;
  
      public DocumentView() {
          setBackground(Color.GRAY);
          this.add(scrollPane);
          setVisible(true);
  
          addMouseListener(this); //za kontra focus
      }  
  }
  </code></pre>
  
  <h2>What is not working</h2>
  
  <p>it is supposed to be a document and you can add pages in it...So when I add more than 2 pages in one document it can not show all it just adds them but I can't see them...that is way I need scroll bar....not working , I mean it doesn't add scroll when I add more than 2 pages.</p>