title: How do i get vertical scrolling to JPanel?
body: <p>I have written a code in java using swing, so that I will have a JscrollPane added to JPanel and then I will add buttons of fixed size to JPanel in vertical fashion </p>
  
  <pre><code>    JPanel panel=new JPanel();
      panel.setBackground(Color.WHITE);
  
      int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
      int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS; 
      JScrollPane jsp=new JScrollPane(panel,v,h);
      jsp.setPreferredSize(new Dimension(600,600));
      jsp.setBounds(150,670,850,200);
      frame.add(jsp);
  </code></pre>
  
  <p>then I am adding buttons to it at run time.</p>
  
  <pre><code>     for(i=0;i&lt;n;i++) 
      {
           button[i]=new JButton();
           button[i].setBounds(20,y,120,120);
           button[i].setSize(120,120);
           button[i].setToolTipText(file[i].toString());       
           button[i].setIcon(Icon);
           panel.add(button[i]);   
           y=y+140;
       }
  </code></pre>
  
  <p>I want to add a buttons one below the other...(i.e I want a vertical scrollbar)</p>
  
  <p>i.e. button1</p>
  
  <pre><code> button2
  
     '
  
     '
  </code></pre>
  
  <p>but above code is giving me buttons in a line (i.e. I am  getting horizontal scrollbar)
  i.e. button1  button2...</p>
  
  <p>another problem is the size of the buttons. Using btn.setSize() is not affecting size at all...</p>
  
  <p>can anybody help me?</p>