JTextPane and insert

Hello,

I'm using a JTextPane and now I want to insert some RTF formatted text. The RTF formatted text is being readed out of a database.

Here is an example for the formatted text which is stored in the database:

{\\rtf1\\ansi\n{\\fonttbl\\f0\\fnil Monospaced;\\f1\\fnil Tahoma;\\f2\\fnil Arial;}\n

{\\stylesheet{\\s3\\li0\\ri0\\fi0\\sbasedon4default;}

{\\s1\\sbasedon2default;}

{\\s2\\sbasedon3default;}

{\\s4\\f1\\fs22\\i0\\b0default;}}\n

\\paperw11905\\paperh16837\\margl1273\\margr1273\\margt1417

\\margb1134\n\\s1\\li0\\ri0\\fi0\\ql\\f2\\fs24\\i0\\b0\\ul0\\cf0 Yours

sincerely\\f1\\fs22\\ul0\\par\n

And now this RTF formatted text should be inserted in a JTextPane. But the JTextPane is not empty, so the text should be inserted at the current position of the cursor. How can I do this?

Greeting Markus!

[1362 byte] By [elliot2extremea] at [2007-11-26 14:32:37]
# 1
Search the forum before you ask a trivial question: http://forum.java.sun.com/thread.jspa?forumID=57&threadID=701177
Rodney_McKaya at 2007-7-8 2:28:09 > top of Java-index,Desktop,Core GUI APIs...
# 2

Hello,

I have searched the forum, but when I'm using this way and insert the above listed RTF formatted text the complete text with all RTF instructions will be inserted.

I want to insert only the real text without the RTF instructions and the text should be formatted correctly. The selected font, fontsize and so on.

Greetings Markus

elliot2extremea at 2007-7-8 2:28:09 > top of Java-index,Desktop,Core GUI APIs...
# 3
StyledDocument sd = pane.getStyledDocument(); Reader reader = new StringReader(text2);RTFEditorKit rtf = new RTFEditorKit();rtf.read(reader, sd, doc.getLength());
Rodney_McKaya at 2007-7-8 2:28:09 > top of Java-index,Desktop,Core GUI APIs...
# 4

Hello

now it works the text is inserted correct. But there is one problem. How can I insert the text at the current position of the cursor.

I tried the following way:Reader reader = new StringReader(oTextModule.toString());

RTFEditorKit rtf = new RTFEditorKit();

rtf.read(reader, doc, textpane.getCaretPosition());

But this way won't work correct.

elliot2extremea at 2007-7-8 2:28:09 > top of Java-index,Desktop,Core GUI APIs...
# 5
What happened when you used the insertString(...) method given to you in the first reply?
camickra at 2007-7-8 2:28:09 > top of Java-index,Desktop,Core GUI APIs...
# 6

Hello,

when I'm using the method insertString(...) it insert the complete RTF Code like this:

{\\rtf1\\ansi\n{\\fonttbl\\f0\\fnil Monospaced;\\f1\\fnil Tahoma;\\f2\\fnil Arial;}\n

{\\stylesheet{\\s3\\li0\\ri0\\fi0\\sbasedon4 default;}

{\\s1\\sbasedon2 default;}

{\\s2\\sbasedon3 default;}

{\\s4\\f1\\fs22\\i0\\b0 default;}}\n

\\paperw11905\\paperh16837\\margl1273\\margr1273\\margt1417

\\margb1134\n\\s1\\li0\\ri0\\fi0\\ql\\f2\\fs24\\i0\\b0\\ul0\\cf0 Yours

sincerely\\f1\\fs22\\ul0\\par\n

elliot2extremea at 2007-7-8 2:28:09 > top of Java-index,Desktop,Core GUI APIs...
# 7
Hello,does nobody have an idea how I can insert the text with the function RTFEditorKit.read(...) at the current position of the cursor.Markus
elliot2extremea at 2007-7-8 2:28:09 > top of Java-index,Desktop,Core GUI APIs...