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

Newline makes JOptionPane render closing html tag

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

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

      A DESCRIPTION OF THE PROBLEM :
      When using HTML in the "message" of a JOptionPane, newlines in the HTML string will cause the closing HTML tag to be rendered to the screen.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See attached test case

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Literal HTML tags should not be rendered.
      ACTUAL -
      The closing HTML tag is shown in the component.

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      import javax.swing.JOptionPane;

      public class Main
      {
      public static void main(String[] args)
      {
      // This dialog will be shown correctly. It uses the <BR/> element
      // (using <BR/> shows a '/' with Java 5, but works with Java 6, both work with just <BR>)
      JOptionPane.showConfirmDialog(null, "<html>Newlines break HTML rendering in the component:<ul><li>This is without newlines</li></ul><br><br />See the next dialog</html>");
      // This dialog uses newlines and incorrectly shows the closing HTML tag on both Java 5 and Java 6
      JOptionPane.showConfirmDialog(null, "<html>Newlines break HTML rendering in the component:<ul><li>This is with newlines, the html closing tag will be shown</li></ul>\n\nTold ya! </html>");
      }

      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Always use HTML line breaks (<BR>) instead of newlines.
      For compatibility with Java 5 do not use <BR/>, because Java 5 will render the slash character '/'

            shickeysunw Shannon Hickey (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: