Lines of text on JEditorPane

I need to open an ASCII text file, read the lines (one by one) and add then to a JEditorPane. I cannot use the reader like this:

FileReader reader =new FileReader(dataFile);

dataDisplay.read(reader,null);

because I have to do some manipulation with the lines first. Anyway, the point is that I have no idea how to add the lines one by one. I tried this:

while (line !=null ){

line = in.readLine();

dataDisplay.setText(line);//dataDisplay is my JEditorPane

}

but I end up with just the last line of the file in display. Any suggestions?

Thanks!

[823 byte] By [lgarcia3a] at [2007-10-2 6:55:26]
# 1

Calling JEditorPane.setText(str) replaces whatever is currently in the pane with the contents of str. Instead you need to build-up a string with either a StringBuffer or a String.

Example:

StringBuffer sb = new StringBuffer();

while (line !=null ){

line = in.readLine();

sb.append(line);

}

dataDisplay.setText(sb.toString()); //dataDisplay is my JEditorPane

Hope this helps,

Nate

nbloma at 2007-7-16 20:23:25 > top of Java-index,Desktop,Core GUI APIs...
# 2
Almost forgot.The reason to use a StringBuffer instead of a String and the '+' operator is that a StringBuffer doesn't re-allocate the string contents each time it is appended to.
nbloma at 2007-7-16 20:23:25 > top of Java-index,Desktop,Core GUI APIs...
# 3
> but I end up with just the last line of the file in display. Any suggestions?Use a JTextArea and the append(...) method. A text area is more efficient if you don't need any special attributes for each line of text.
camickra at 2007-7-16 20:23:25 > top of Java-index,Desktop,Core GUI APIs...