By default, the line wrap property is set to false. You should set it to true. You should a
// JTextArea(allDetails, 20, 60); sets rows and columns. instead of setting
// a size for the text area.
JTextArea text = new JTextArea(allDetails, 20, 60);
text.setEditable(false);
text.setLineWrap(true);
text.setWrapStyleWord(true); // wrap style if by word instead of chararcter
...
displayFrame.pack();
See Javadoc for JTextArea
You have already put the textArea in the ScrollPane. You only need to add the ScrollPane to the frame.
displayframe.add(scroll);
See this running example
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
public class TestTextArea {
private JScrollPane jsp;
private JFrame frame = new JFrame();
public TestTextArea() {
String hello = "hello hello hello hello hello hello hello "
+ "hello hello hello hello hello hello hello "
+ "hello hello hello hello hello hello hello "
+ "hello hello hello hello hello hello hello "
+ "hello hello hello hello hello hello hello ";
JTextArea text = new JTextArea(hello, 10, 50);
text.setLineWrap(true);
text.setWrapStyleWord(true);
jsp = new JScrollPane(text);
frame.add(jsp);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run() {
new TestTextArea();
}
});
}
}