Question: Can anybody tell me what is the problem in following program? I want to fit `JScrollPane` on `JtextArea` but when I add it then `JTextArea` is not visible.

```
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class Area extends JFrame
{
    private JTextArea ta;
    private JTextField tf;
    JScrollPane jp;

    public Area()
    {
       super("Text Area");
       tf=new JTextField();
       tf.setBounds(100,350,300,30);
       add(tf);
       ta=new JTextArea();
       ta.setBounds(100,100,300,200);
       jp= new JScrollPane(ta);
       add(jp);
       setLayout(null);
       setSize(500,500);
       setVisible(true);
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }

   public static void main(String...s)
   {
      new Area();
   }
}

```

Answer: 
I see several problems:

* Don't use a `null` layout; do use a real [layout](http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html).
* The default layout of `JFrame` is `BorderLayout`; the default position is `CENTER`; only one component can occupy a position at a time; the example below uses `NORTH` & `CENTER`.
* Use the appropriate constructor parameters to size the text components initially.
* The scrollbar will appear automatically whenever the scrollpane is smaller than the enclosed component; resize the frame to see the effect.
* As shown [here](https://stackoverflow.com/a/7229662/230513), the frame's size is made smaller for effect.
* See also [*Initial Threads*](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html).

![image](https://i.stack.imgur.com/SjX5E.png)

```
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/** @see https://stackoverflow.com/a/19215436/230513 */
public class Area extends JFrame {

    public Area() {
        super("Text Area");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JTextField tf = new JTextField(12);
        add(tf, BorderLayout.NORTH);
        JTextArea ta = new JTextArea(24, 12);
        JScrollPane jp = new JScrollPane(ta);
        add(jp, BorderLayout.CENTER);
        pack();
        // arbitrary size to make vertical scrollbar appear
        setSize(240, 240);
        setLocationByPlatform(true);
        setVisible(true);
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Area();
            }
        });
    }
}

```
sounds like its added but its not shown because of the policy try this:

```
  jp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  jp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

```