[英]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);
您需要将JTextArea
添加到滚动窗格中
JScrollPane scrollPane = new JScrollPane(area);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.