Omnimaga

General Discussion => Technology and Development => Computer Programming => Topic started by: Snake X on June 06, 2011, 10:19:54 pm

Title: JTextArea getText funtion?
Post by: Snake X on June 06, 2011, 10:19:54 pm
Ok, so If I have a JTextArea called input, and I want to make a string that comprises of what is inside the textbox (upon clicking a button via buttonListener), how can I do this?

String link = input.getText(); //something like this im sure.. though this isn't it.

^ thats pretty much what im trying to do
Title: Re: JTextArea getText funtion?
Post by: cooliojazz on June 06, 2011, 11:48:22 pm
Depenends on if you want the plain text or not.  If you want the actuall contents (EG html tags if it's type text/html , or rtf tags if it's text/rtf) or it's just type text/plain, just use input.getText(), if you're using any "rich" text format but you still just want the plain text, you can use input.getDocument().getText(0, input.getDocument().getLength());
Okay, I just wrote all that, then realized you said jtextarea, not jeditorpane or jtextpane, so everything i dsaid about rich text is inapplicable. =\ Anywasy, input.getText() is correct, why did you think it wasn't?
Title: Re: JTextArea getText funtion?
Post by: Snake X on June 08, 2011, 08:06:55 am
because I had this and it didn't setText:

Code: [Select]
String link = input.getText();
output.setText(link);

There wasn't anything in the ouput JTextArea even though I put something in it