joseph
joseph

Reputation: 129

Simple question about JTextArea

I want to create a blank text area in which the user can enter a few sentences, and then, when the user closes the window (or before), I want to save this text in a string (and print it just to test that it works). So far, the code I have written does not work:

JTextArea area = new JTextArea(5,20);
JScrollPane scrollPane = new JScrollPane(q); 
JFrame frame = new JFrame("TextDemo");
frame.add(scrollPane);
frame.pack();
frame.setVisible(true);
String paragraph_text = area.getText();
System.out.println(paragraph_text);

Upvotes: 1

Views: 325

Answers (1)

Grammin
Grammin

Reputation: 12205

You need to add your JTextArea to the scrollpane

JScrollPane scrollPane = new JScrollPane(area); 

Upvotes: 1

Related Questions