title: JAVA JScrollPane not showing up
body: <p>I have a JPanel with scrollbar and i want to add a lot of JLabels to it. But the scrollbar doesnt work . I can not use the scrollbar and even after the panel is full it doesn't scroll . Here is my code  :</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.*;
  
  
  public class Scroll {
  public static void main(String[] args) {
      JPanel panel = new JPanel(new GridLayout(0,1));
      JPanel p = new JPanel(new BorderLayout());
      JScrollPane scroll = new JScrollPane(panel);
      scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
      p.add(scroll, BorderLayout.NORTH);
      JButton but = new JButton("OK");
      p.add(but, BorderLayout.SOUTH);
      but.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e){
              panel.add(new JLabel("Some random text"));
              scroll.revalidate();
              p.repaint();p.revalidate();
          }
      });
      JFrame frame = new JFrame();
      frame.setSize(800,200);
      frame.setVisible(true);
      frame.add(p);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setLocationRelativeTo(null);
  }
  }
  </code></pre>