-3

Possible Duplicate:
Java Textarea ScrollPane

I have code for a scrollbar to appear in a textarea but it doesnt really work. Any suggestions?

    final JTextArea textArea = new JTextArea();
    textArea.setEditable(false);
    textArea.setBounds(10, 152, 456, 255);
    textArea.setBorder(border);
    textArea.setLineWrap(true);
    sbrText = new JScrollPane(textArea);
    sbrText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    panel_1.add(textArea);
Community
  • 1
  • 1
Pita
  • 498
  • 5
  • 11
  • 21

1 Answers1

5

You need to add the JScrollPane to the panel, not the JTextArea. So instead it should be:

panel_1.add(sbrText);
btantlinger
  • 803
  • 8
  • 11
  • I tried that, but it doesnt work. the textarea isnt visible in the frame anymore when i do that – Pita Mar 08 '12 at 20:52
  • 1
    Well no way to know without seeing how your JPanel is created and added to the JFrame. Anyway, you asked this question twice. You should ask on the other question, rather than creating two of the same question. – btantlinger Mar 08 '12 at 20:56