Reputation: 129
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
Reputation: 12205
You need to add your JTextArea
to the scrollpane
JScrollPane scrollPane = new JScrollPane(area);
Upvotes: 1