Search code examples
javaswinguser-interfacejscrollpanejtextarea

Scrollbar not showing up in JTextArea


I'm trying to put a scrolling text area, called descriptionScroll. However, the scroll bar is NOT visible. I've tried many approaches, and all end in frustration.

Am I missing anything to get the scroll bar showing? It should appear to the right of the large text box next to "Description"

Here's the relevant piece of code:

import javax.swing.JScrollPane;
import javax.swing.JTextArea;

protected JTextArea descriptionTextArea;


protected JScrollPane descriptionScroll;


String descriptionText = 
"Lot ID(s):\n" +
"Wafer ID(s):\n" +
"PSPT(Probe Ship Part Type):\n" +
"Tester:\n" +
"Tester Job Name:\n" +
"PID (FPP, FPC):\n" +
"Reprobe required before shipping lot? (Y/N)\n\n" +
"Hold for (individual):\n" +
"Hold for (group)\n" +
"Expected release date\n" +
"Hold Comments:\n\n" +
"Shipping Information:\n" +
"Special Instructions:\n";


public Constructor(){

descriptionTextArea = new JTextArea(descriptionText);
descriptionScroll = new JScrollPane(descriptionTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
add(descriptionTextArea);
add(descriptionScroll);  
pack();

setSize(790, 625);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);


descriptionTextArea.setSize(650, 200);
descriptionTextArea.setLocation(110, 228);
descriptionTextArea.setLineWrap(true);



}

Missing scroll


Solution

  • You're adding both JScrollPane and JTextArea to the same container. Add the JTextArea to JScrollPane:

    descriptionScroll.add(descriptionTextArea);