JTextArea help

Hey guys and gals,

this is probably goign to be a REALLY easy one for everyone (and probably shoudl be for me) but im working on an application that edits a JTextArea at runtime and i have the following method

publicvoid addText(String s)

{

convo.append(s +"\r\n");

}

Anyone know why the newline isnt added to the component?

D

[520 byte] By [Drogo_Nevetsa] at [2007-11-26 20:39:12]
# 1
The Document only stores a "\n" to represent the new line string.If you use the textArea.write(..) method to save the text the appropriate new line string for your platform will be used when saving the text to the file.
camickra at 2007-7-10 1:56:36 > top of Java-index,Desktop,Core GUI APIs...
# 2

I am not trying to save the text to a file, the text when the application finishes can simply be forgotten about.

I just need a new line added at run time

basically a number of system message will appear in the area and at the moment it looks like

message 1message 2message 3

but should look like

message 1

message 2

message 3

D

Drogo_Nevetsa at 2007-7-10 1:56:36 > top of Java-index,Desktop,Core GUI APIs...
# 3
> I just need a new line added at run timeThen using "\n" is all you need.Simple example: http://forum.java.sun.com/thread.jspa?forumID=57&threadID=689486&start=2
camickra at 2007-7-10 1:56:36 > top of Java-index,Desktop,Core GUI APIs...
# 4
public void sendMessage(String s){out.println(s + "\n");}this doesnot work :s
Drogo_Nevetsa at 2007-7-10 1:56:36 > top of Java-index,Desktop,Core GUI APIs...
# 5

I gave you a working example.

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.

camickra at 2007-7-10 1:56:36 > top of Java-index,Desktop,Core GUI APIs...