2

Below is an SSCCE, which wrappes the text on my computer with java version 1.6.0_23, but doesn't on a another computer with java version 1.7.0_17-b02.

OS on both: Windows7 64bit

If I add some spaces in the text, it works on both. So word-wrapping seems to be no problem, but letter-wrapping.

It seems to be a bug, but I couldn't find anything about it. Does anyone know a workaround for that? Thanks!

Here is the SSCCE:

    import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.text.DefaultStyledDocument;

public class TextWrapping
{
    public static void main(final String[] args)
    {
        SwingUtilities.invokeLater(new Runnable()
        {

            public void run()
            {
                final JTextPane p = new JTextPane();
                p.setStyledDocument(new DefaultStyledDocument());
                p.setText("123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x");
                final JFrame f = new JFrame();
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.getContentPane().add(new JScrollPane(p));
                f.setSize(400, 400);
                f.setLocation(0, 0);

                f.setVisible(true);
            }
        });

    }
}
mKorbel
  • 109,525
  • 20
  • 134
  • 319
haferblues
  • 2,155
  • 4
  • 26
  • 39

0 Answers0