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

JTextPane now renders HTML paragraph tags differently in/out of tables

XMLWordPrintable

    • Fix Understood
    • b53
    • 6
    • generic, x86
    • generic, windows_xp

      FULL PRODUCT VERSION :
      [WinXP]
      java version "1.6.0_10-beta"
      Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b23)
      Java HotSpot(TM) Client VM (build 11.0-b11, mixed mode, sharing)

      [Mac OS X]
      java version "1.6.0_05"
      Java(TM) SE Runtime Environment (build 1.6.0_05-b13-120)
      Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_05-b13-52, mixed mode)



      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]
      Mac OS X Version 10.5.2

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Running inside VMWare Fusion virtual machine on Mac.

      A DESCRIPTION OF THE PROBLEM :
      When displaying HTML, a paragraph tag (<p>) is supposed to leave an offset (usually one blank line) above it. This works properly in Java 5. In Java 6, this only works when the paragraph tag is *not* within a table cell. When in a table cell, Java 6 seems to treat paragraph tags like simple line breaks (no blank line above).

      I've tested this on both WinXP and Apple Mac OS X.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See the attached source code. In general, just try using paragraph tags in an HTML doc. Then try again with the text placed inside a table cell.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A paragraph tag should usually leave with a blank space (one line?) above it, to separate itself from any preceding paragraph. This should work the same whether the content is in the HTML's main body, or within a table.
      ACTUAL -
      In Java 6 only, the content within a table does not include a blank space above paragraphs.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.util.Iterator;
      import javax.swing.*;


      /**
       * Test the handling of paragraph tags in/out of a table cell.
       * Demonstrates that paragraphs tags (&lt;p>) within a table are
       * treated as simple line breaks, without the expected extra space above.
       * This unexpected behavior started in Java 6. Java 5 treats paragraph tags
       * consistently, whether in tables or not.
       */
      public class ParagraphInTable extends JFrame
      {
      private JTextPane descriptionArea;

      public ParagraphInTable()
      {
      super("ParagraphInTable");
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      descriptionArea = new JTextPane();
      descriptionArea.setEditable(false);
      descriptionArea.setContentType("text/html");
      descriptionArea.setMargin(new Insets(5,5,5,5));
      Container cp = getContentPane();
      cp.setLayout(new BorderLayout());
      cp.add(descriptionArea, "Center");
      setSize(500,500);
      }


      private String getSystemJavaProperties()
      {
      StringBuilder sb = new StringBuilder();
      for (Iterator it=System.getProperties().keySet().iterator(); it.hasNext(); )
      {
      String key = it.next().toString();
      if (key.startsWith("java.vm."))
      {
      sb.append(key).append("=").append(System.getProperty(key)).append("\n");
      }
      }
      return sb.toString();
      }


      public void setHtml()
      {
      String paragraphs =
      "<p>This is a first paragraph.</p><p>This is a second paragraph. "+
      "Notice that there should be a reasonable space between this paragraph "+
      "and the one above; usually the offset is one full blank line. In "+
      "Java 5 this works whether in a table or not. In Java 6, the table "+
      "version loses the spacing.</p>";
      StringBuilder html = new StringBuilder();
      html.append("<html>\n");
      html.append(paragraphs);
      html.append("\n<br>\n<table border=1><tr><td bgcolor=silver>");
      html.append(paragraphs);
      html.append("\n</td></tr></table>\n");
      html.append("<p><br><hr><pre><small>");
      html.append(getSystemJavaProperties());
      html.append("</small></pre></p></html>\n");
      descriptionArea.setText(html.toString());
      }


      public static void main(String[] args)
      {
      ParagraphInTable pit = new ParagraphInTable();
      pit.setVisible(true);
      pit.setHtml();
      }

      }


      ---------- END SOURCE ----------

      Release Regression From : 5.0
      The above release value was the last known release where this
      bug was not reproducible. Since then there has been a regression.

            peterz Peter Zhelezniakov
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: