Java Swing,textarea 作为输入/输出?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/234587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Swing, textarea as input/output?
提问by Jean Paul Galea
回答by Paul Brinkley
JTextAreas are editable by default, so input is trivial. Just put one into a test UI and see for yourself.
JTextAreas 默认是可编辑的,因此输入很简单。只需将一个放入测试 UI 中并亲自查看即可。
From a design perspective, using the same JTextArea for both input and output strikes me as unwise. The only example I can think of is a shell interface, and that imposes stronger limits on how input and output works than a JTextArea will provide out of the box.
从设计的角度来看,对输入和输出使用相同的 JTextArea 使我感到不明智。我能想到的唯一示例是 shell 接口,它对输入和输出的工作方式施加了比 JTextArea 开箱即用的更强的限制。
回答by micro
I'm not sure if I got the point of your question, but you can get the text the user has typed in using the getText() method:
我不确定我是否明白您的问题,但是您可以使用 getText() 方法获取用户输入的文本:
JTextArea ta = new JTextArea(); String input = ta.getText();
JTextArea ta = new JTextArea(); 字符串输入 = ta.getText();
回答by Anon
Check out this Sun toturial:
看看这个Sun totutorial:
http://java.sun.com/docs/books/tutorial/uiswing/components/textarea.html
http://java.sun.com/docs/books/tutorial/uiswing/components/textarea.html
In particular, scroll down to the "TextAreaDemo" example.
特别是,向下滚动到“TextAreaDemo”示例。

