Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8194161

Line wrapping of JTextPane incorrect

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Version:
      7
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_151"
      Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      The wrapping of text chunks with different attributes (styled fragments) works incorrectly.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached code and start typing at the beginning of the document (the empty line above the preset text).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No changes in second paragraphs wrapping.
      ACTUAL -
      With every typed letter the wrapping of the second paragraph changes.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import java.awt.BorderLayout;
      import javax.swing.*;
      import javax.swing.event.*;
      import javax.swing.text.*;

      public class BugWrapJava7 extends JFrame {

          JTextPane jtp;
          StyledDocument doc;

          public BugWrapJava7() {
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setLayout(new BorderLayout());
              jtp = new JTextPane();
              add(jtp, BorderLayout.CENTER);
              jtp.setText("\ntype some text in the above empty line and check the wrapping behavior");
              doc = jtp.getStyledDocument();
              doc.addDocumentListener(new DocumentListener() {
                  public void insertUpdate(DocumentEvent e) {
                      insert();
                  }
                  public void removeUpdate(DocumentEvent e) {
                  }
                  public void changedUpdate(DocumentEvent e) {
                  }
              });
              setSize(200, 200);
              setVisible(true);
          }
          public void insert() {
              SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      Style defaultStyle = jtp.getStyle(StyleContext.DEFAULT_STYLE);
                      doc.setCharacterAttributes(0, doc.getLength(), defaultStyle, false);
                  }
              });
          }
          public static void main(String[] args) {
              new BugWrapJava7();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      A workaround was posted on "http://java-sl.com/tip_java7_text_wrapping_bug_fix.html", but it slows down to much with large texts (up to 50-60 pages).

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              psadhukhan Prasanta Sadhukhan
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated: