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?


Asked by: Sienna102 | Posted: 28-01-2022






Answer 1

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.

Answered by: Maya188 | Posted: 01-03-2022



Answer 2

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();

Answered by: Melissa113 | Posted: 01-03-2022



Answer 3

Check out this Sun toturial:

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

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

Answered by: Brad924 | Posted: 01-03-2022



Similar questions

jar - input/output with Java Web Start

I'm working on converting a very simple java desktop application to run in java web start and I'm having all kinds of trouble with the input/output files. Most specifically I can't seem to find any information on how to handle i/o in a web start application. I tried placing the input files in the same folder on my web server as the jar and jnlp file, but it doesn't read it. I've got one input file that I want to ...


Keeping input/output separated in Java console application

I am writing a console application in Java. It is similar to a chat client: Input and output are asynchronously made. The problem is that if some output is made while the user is in the middle of typing, the lines will get mixed up on the screen. I am looking for a solution which allows me to have a input area separate from the output area. At the moment I am using an extra thread which polls a BufferedReader on Sy...


Proxy input/output stream issues in Java

I've been trying for a while a few different methods to get my custom proxy to work, and the only way I've been able to so far is through use of Apache's HttpClient. However, for the sake of knowing, I was wondering why I'm having trouble with my own proxy handle implementation below: public void processProxyRequest (Socket client, String request) throws Exception { if ( !request.equals("") ) { ...


Java Input/Output streams with .exe

What I want to do is, launch a .exe console program with Java, and use Java to manipulate the input and output streams from the console window. I know I can get the input and output streams from an application, and this is how I am currently doing it: try { process = Runtime.getRuntime().exec("C:\\Users\\Owner\\Documents\\testApp\\console.exe"); } catch (IOException e1) { e1.printSta...


java - JBoss input/output streaming

I'm have a deal with Spring MVC based application deployed under JBoss-4.2.3.GA and want to clarify how servlet input/output streaming works with huge requests/responses body. I'm bother about it because don't want to keep whole request/response in memory until call will be completely finished. How can I detect exactly input/output stream implementation that JBoss passes to servlet? Or possible I can investigate it...


java - Does it really matter the size of the objects you send through a Socket with object input/output streams?

Is it more efficient to flush the OutputStream after each individual invocation of ObjectOutputStream#writeObject rather than flushing the stream after a sequence of object w...


Input/output help with a .jar in Java?

Feel free to jump to the tl;dr. This is how my usual experience with my .jar is, in command: java -cp test.jar test q a o to open the jar Next, something like UF UD UR etc, enter to the program This gives me maybe 20 lines of 'response' I want to do the following: 1 - run the jar using paramaters like above These parameters should be determined by th...


java - Should I have two threads for input/output or use NIO?

I have been working on a (relatively) simple tcp client/server chat program for my networking class. The problem that I am running into is I am using blocking calls, such as read() and writeBytes(). So, whenever I try to send a message to my server, the server does not print it out until it writes one back. For this situation, would using one thread for input and one thread for output be the most ...


java - Simple input/output applet with text boxes

I have a console application that uses System.out.println's to output text. What I want to do is turn it into an applet, where instead of System.out.println's, it displays the text in a text box. Is there a relatively easy way to convert this?


networking - Multiple Input/Output streams in Java?

I ran into a problem while using input/output streams in Java. My thought was to have a DataInputStream to handle receiving text and a PrintStream to pass messages to the server from the server and object(output/input)streams to handle passing piece movements and current board image. My problem is that the code hangs while it is trying to create the ObjectInputStream in the co...






Still can't find your answer? Check out these amazing Java communities for help...



Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)



top