Q: Wont show scrollbar The vertical scrollbar won't show. Here is my code.
The java frame shows the textarea but the scrollbar for the textarea is not showing. I'm a green programmer so I dont have much clue of what I'm doing.
What should I do to make the scrollbar show?
Please see my code and find my mistake.
I want the scrollbar to show on the JTextArea
import javax.swing.*;//imported for the frame of the chatbot
import java.awt.*;
import java.awt.event.*;

public class Bot extends JFrame{
    private JTextArea Chatarea = new JTextArea(10,20);
    private JTextField Chatbox = new JTextField();
    private JScrollPane Scroll = new JScrollPane(Chatarea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);


    public Bot(){//frame for the chatbot
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
        frame.setVisible(true);
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);
        frame.setLayout(null);
        frame.setSize(600 , 600);
        frame.setTitle("JAVADDY");
        frame.add(Chatarea);
        frame.add(Chatbox);// 


        //for chat area
        Chatarea.setSize(560, 400);
        Chatarea.setBackground(Color.YELLOW);
        Chatarea.setLocation(2, 50);
        Chatarea.setLineWrap(true);
        Chatarea.setEditable(false);//make jtextarea uneditable     
        //for chat box 
        Chatbox.setSize(540, 30);
        Chatbox.setLocation(2, 500);

        //for scrolling
        Scroll.setSize(1024,800);
        Scroll.setVisible(true);        

        Chatbox.addActionListener(new ActionListener(){
            //@Override
            public void actionPerformed(ActionEvent arg0){
                String gtext = Chatbox.getText();
                Chatarea.append("You -> "+ gtext+"\n");
                Chatbox.setText("");


                //place algorithm here
                if(gtext.contains("Hello")){
                    //find way to connect to database
                    bot("Hi");
                }
                else{
                    bot("I don't understand.");
                }
            }

        });         

    }// end of frame for the chatbot

    private void bot(String string){
            Chatarea.append("Bot ->" +string+"\n");
        }

    public static void main(String[] args){
        new Bot();
    }
}


A: Question
Did you use JScrollPane.setViewport(what's inside the JScrollPane)?
Try: Scroll.setViewport(Chatarea);
What, why and how
If all JScrollPane's contents fit, then the scroll bar is hidden. When JScrollPane has many big elements inside it, a scroll bar will be shown, in order to scroll thru it.
Try this
Add many buttons or labels inside your JScrollPane to see, if the scroll bar appears, if not, we will find out why

A: While YoungDev offers good advice, the problem is actually here:
Chatarea.setSize(560, 400);

Don't set the size of the JTextArea, since this constrains it to never expand when it needs to. Instead set its column and row properties which constrains the visible columns and rows, but does not constrain its actual size, allowing it to expand.
And also get rid of this:
frame.setLayout(null);

as you're shooting yourself in the foot by ignoring the layout managers.
