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!
# 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
# 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.
# 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