Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Working with JTextArea

I am writing a simple text editor, I am having problems with a JTextArea.

I can enter text and everything is fine, but when I save it into a text file the line breaks are not recognized. If i open that file with notepad it simply shows a box in place of the line break. Also when I load that text file into the JTextArea the boxes are not there, and the line breaks are just not present.

My second problem is printing. I found a way to print text to the printer, using a print stream, but when I print anything from my TextArea each line is tabbed over.

Example

Text
Text
Text
Text

Is there any way I can fix that, or is there a different way to print text to the default printer?

Thanks in advance
[802 byte] By [Wizard1988] at [2007-11-11 7:26:46]
# 1 Re: Working with JTextArea
Take a look at the API documentation for JTextArea - you'll see a reference to the "DefaultEditorKit" class of javax.swing.text "for a discussion on how newlines are handled."

There is a tutorial on text components which you can find at:

http://java.sun.com/docs/books/tutorial/uiswing/components/text.html
nspils at 2007-11-11 22:38:16 >