Hello All,

As I did not get any help from java forum, I am placing this post here.

In my java application, I am using JTextPane as a text editor to create RTF text. The problem I observed with the JTextPane on Ubuntu 8.04 is: whenever I am changing any of the text property (font color, font name, font style like bold, italic or underline) and then enter the characters without providing space, the whole word gets wrapped to the next line from the point where exactly the property change starts i.e. the new formatted text is jumped to the next line from the starting point of formatting.

My requirement is, as I am not adding any space character while changing the property, the characters should be entered in the sequence and should come to new line as per normal word-wrap rule, as happens in normal RTF editors.

Can anybody help me out in this regards with some solution as it’s a very urgent requirement?

Below I am also providing the sample code to check the behavior. There is no dynamic facility to change the property, I am providing the text with multiple formatting settings through code itself. To reproduce the above issue, just type the characters from the property change point, you will see the whole word jumping to new line.


Code:
import javax.swing.*;
import javax.swing.text.*;

public class TestWrapping {

    JScrollPane scroll;
    JEditorPane edit;

    public TestWrapping()  throws Exception {
        final JFrame frame=new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        edit=new JEditorPane();
        edit.setEditorKit(new StyledEditorKit());
        scroll=new JScrollPane(edit);
     edit.getDocument().insertString(0,"11111111111111222222222222222222222222222222222222222",null);
        MutableAttributeSet attrs=new SimpleAttributeSet();
        StyleConstants.setBold(attrs,true);
        ((StyledDocument)edit.getDocument()).setCharacterAttributes(30,5,attrs,false);
        StyleConstants.setUnderline(attrs,true);
        ((StyledDocument)edit.getDocument()).setCharacterAttributes(35,5,attrs,false);
        StyleConstants.setFontSize(attrs,25);
       ((StyledDocument)edit.getDocument()).setCharacterAttributes(40,5,attrs,false);
        frame.getContentPane().add(scroll);
        frame.setBounds(0,0,150,150);
        frame.show();
   }

   public static void main(String[] args) throws Exception {
        new TestWrapping();
    }
}
If you need any additional information, please let me know.

Thanks in advance.

Regards,
VPKVL