Pasting on a JTextField

Hello,

Here is my problem.

I am copying a fragment of text(~100 characters) from a file opened with any editor and I paste it on a JTextField. The text that I copied is about 4-5 lines and each line is seperated with a CRLF bicharacter( 0x0D,0x0A ). The problem is thta when I paste the text on the JTextField(or a JTextArea) the CRLFs are replaced with a linefeed character (0x20). Is there any way to prevent this replace?

Thanks in advance.

[468 byte] By [bankerera] at [2007-10-3 8:46:41]
# 1

> CRLFs are replaced with a linefeed character (0x20).

x20 is a space character so this makes sense for a JTextField

for a JTextArea the Document only store a "\n" in the Document to represent the newline string. If you use the textArea.write(...) method the "\r\n" is inserted into the file correctly.

You could try using a JTextPane. Again the Document only stores the "\n" to represent the newline buy then try using:

textPane.getText();

textPane.getDocument().getText()

One method will return the text with just the "\n" character, the other will return the "\r\n" character.

camickra at 2007-7-15 3:55:42 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanks a lot!!! I used a StringWriter and a write(StringWriter) end then a StringWriter.toString().
bankerera at 2007-7-15 3:55:42 > top of Java-index,Desktop,Core GUI APIs...