[英]Java Swing, textarea as input/output?
JTextAreas are editable by default, so input is trivial. JTextAreas默认情况下是可编辑的,因此输入很简单。 Just put one into a test UI and see for yourself.
只需将一个放入测试用户界面,然后自己查看即可。
From a design perspective, using the same JTextArea for both input and output strikes me as unwise. 从设计的角度来看,对输入和输出使用相同的JTextArea使我感到不明智。 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开箱即用的方式更严格的限制。
Check out this Sun toturial: 看看这个Sun toturial:
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”示例。
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(); JTextArea ta =新的JTextArea(); String input = ta.getText();
字符串输入= ta.getText();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.