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

JEditorPane does not recalculate paragraph height properly on resize

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10, OpenJDK 21.0.2. Also reproducible on latest (at the moment of submitting) early access build 23-ea+16-1297

      A DESCRIPTION OF THE PROBLEM :
      JEditorPane does not recalculate paragraph height properly when it is being resized horizontally if paragraph consists of elements with different heights (text with different font sizes, for example).
      This may lead to drawing paragraph contents over content from next elements in HTML document. See image in 'Expected result' for example of such behavior

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile and run attached source code. New window will appear that has following text
      "prefix bigtext1 bigtext2 suffix
      Footer text"
      2. Start shrinking the window horizontally slowly, so "suffix" part of the text gets wrapped on the new line like so:
      "prefix bigtext1 bigtext2
      suffix
      Footer text"
      3. Continue shrinking the window to make "bigtext2" also wrap on the second line.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Height of the paragraph containing "prefix bigtext1 bigtext2 suffix" text is increased and it does not overlap the "Footer text"
      ACTUAL -
      Height of the paragraph containing "prefix bigtext1 bigtext2 suffix" text is not updated after "bigtext2" is wrapped and it is drawn on top of "Footer text". See image at <link>

      ---------- BEGIN SOURCE ----------
      package html_height_bug;

      import javax.swing.*;
      import java.awt.*;

      public class Main {
          private static void swingMain() {
              JFrame frame = new JFrame("html_height_bug");
              frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

              JEditorPane p = new JEditorPane();
              p.setContentType("text/html");
              p.setText("<html><body>"
                      + "<div>"
                      + " prefix"
                      + " <strong style=\"font-size: 30px\">bigtext1</strong>"
                      + " <strong style=\"font-size: 30px\">bigtext2</strong>"
                      + " suffix"
                      + " </div>"
                      + "<p>Footer text</p>"
                      + "</body></html>");
              p.setEditable(false);
              p.setCaret(null);

              frame.getContentPane().add(p);

              frame.setMinimumSize(new Dimension(300, 300));
              frame.pack();
              frame.setVisible(true);
          }

          public static void main(String[] args) {
              SwingUtilities.invokeLater(() -> swingMain());
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        1. Capture.png
          Capture.png
          13 kB
        2. From_submitter.png
          From_submitter.png
          33 kB
        3. Main.java
          1 kB

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

              Created:
              Updated: