You can run the following code.It works in java 7
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.basic;
import javax.swing.*;
/**
*
* @author mac
*/
public class ScrollDemo extends JFrame {
public ScrollDemo() {
JTextArea txtArea = new JTextArea(20,20);
txtArea.setAutoscrolls(true);
txtArea.setEditable(true);
JPanel panel= new JPanel();
panel.add(txtArea);
JScrollPane scrollPane = new JScrollPane(panel);
// scrollPane.setVerticalScrollBar(JScrollBar.VERTICAL);
setContentPane(scrollPane);
setTitle("scrollpane demo");
setSize(300,300);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[])
{
new ScrollDemo();
}
}