Find the answer to your Linux question:
Results 1 to 4 of 4
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 ...
  1. #1
    Just Joined!
    Join Date
    Mar 2009
    Posts
    6

    Word wrapping incorrect inside JTextPane of JAVA on Ubuntu 8.04

    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

  2. #2
    Linux Engineer Thrillhouse's Avatar
    Join Date
    Jun 2006
    Location
    Arlington, VA, USA
    Posts
    1,377
    Have you tested this on other platforms? I just tested it on Windows and it doesn't exhibit any of the behavior you describe (i.e. it works as you're expecting it to).

    Maybe you can search the Sun bug database (Bug Database) for a similar problem. This is most likely a bug in Java, if anything.

  3. #3
    Just Joined!
    Join Date
    Mar 2009
    Posts
    6
    Hello ThrillHouse,

    What you mentioned above is absolutely right. The functionality works fine on Windows OS. The problem which I mentioned, occurs only on MAC OS and Linux OS Flavors. As it works fine on Windows, I thought the problem with the other OS implementation of JTextPane. So is there any alternate to resolve this issue?
    And if it’s a bug in java, can you provide me the link, if you have any describing the same. It’s a very urgent requirement for me.

    Thanks in advance.

  4. #4
    Linux Engineer Thrillhouse's Avatar
    Join Date
    Jun 2006
    Location
    Arlington, VA, USA
    Posts
    1,377
    Java is supposed to be platform independent so if it is showing one thing under Linux/Mac and another under Windows then it's a bug. I don't know if a bug has been opened for it already or not but that's why I gave you the link so you can search for it:

    Bug Database

    If you don't find one, you can open one yourself and it will be addressed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...