简体   繁体   中英

Java Swing, textarea as input/output?

I want to load up a window using the java swing, something like this

However I want to be able to use it for text input also not just to dump data into it..

any idea how to do it?

JTextAreas are editable by default, so input is trivial. 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. 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.

Check out this Sun toturial:

http://java.sun.com/docs/books/tutorial/uiswing/components/textarea.html

In particular, scroll down to the "TextAreaDemo" example.

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:

JTextArea ta = new JTextArea(); String input = ta.getText();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM