Search code examples
javajtextarea

Scrollable in JTextArea


I have a class extending JFrame and a JTextArea with the configuration below. For some reason my Scroll doesn not appear. I can't figure out why.

     JTextArea ta=new JTextArea();
         ...

            ta.setText(out);
            JScrollPane scrollFrame = new JScrollPane(ta);
            //ta.setAutoscrolls(true);
            scrollFrame.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            scrollFrame.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
            add(scrollFrame);
            add(ta);
            setSize(300, 300);
            setResizable(false);
            setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
            setVisible(true);

For example, Adding a Scrollable JTextArea (Java)


Solution

  • just add the scrollframe and not the JTextArea

     add(scrollFrame);
    // add(ta);