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

loading HTML with comment in an editable JEditorPane causes problem comment row

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 6
    • client-libs

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


      ADDITIONAL OS VERSION INFORMATION :
      tested on:
      Linux 2.6.22-14-generic #1 SMP Tue Feb 12 07:42:25 UTC 2008 i686 GNU/Linux
      Ubuntu Hardy release

      A DESCRIPTION OF THE PROBLEM :
      Loading HTML into an editable JeditorPane causes in the position where the comment would be in the code, a row of comment data in white (even if the background of the pane is another color).

      Setting the JEditorPane to read-only via the 'setEditable' function
      eg. editorPane.setEditable(false);
      and re-running the code, will not show this comment problem.

      I am assuming that this is unintended (as it is very unexpected that I comment should show up in html view).







      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      load this text as a html file using the sample code given below:
      After you have run once with results as explained, un-comment the command
      // editorPane.setEditable(false);
      and run again. This time results will be as expected.


      <!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html>
      <head>
      <title>simple document</title>
      </head>
      <body>
      <p>a simple paragraph</p>
      <!-- hello --> again
      <p>another simple paragraph</p>
      </body>
      </html>




      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      1. Only see the results of rendering html code.
      2. Not to see evidence in the editor of any html styled comments
      3. read-only flag not make any difference to the rendering of the editor pane
      ACTUAL -
      see the text within the html comment 'hello' enclosed within a white text field like boundary.


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      none.

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      import java.awt.BorderLayout;
      import java.awt.Container;
      import java.awt.event.ActionEvent;
      import java.io.FileReader;
      import java.io.IOException;

      import javax.swing.AbstractAction;
      import javax.swing.Action;
      import javax.swing.JButton;
      import javax.swing.JEditorPane;
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JScrollPane;
      import javax.swing.text.JTextComponent;
      import javax.swing.text.html.HTMLDocument;
      import javax.swing.text.html.HTMLEditorKit;
      import javax.swing.text.html.parser.ParserDelegator;

      public class HtmlViewer {

      public static void main(String args[]) {
      final String filename = "/home/sean/Desktop/tinytest.xhtml";
      JFrame frame = new JFrame("Loading/Saving Example");
      Container content = frame.getContentPane();

      final JEditorPane editorPane = new JEditorPane();
      // editorPane.setEditable(false); // uncomment this to make comment invisible
      JScrollPane scrollPane = new JScrollPane(editorPane);
      content.add(scrollPane, BorderLayout.CENTER);

      editorPane.setEditorKit(new HTMLEditorKit());
      editorPane.setBackground(new java.awt.Color(252, 171, 193));
      editorPane.setContentType("text/html");

      JPanel panel = new JPanel();

      // Setup actions
      Action loadAction = new AbstractAction() {
      {
      putValue(Action.NAME, "Load");
      }

      public void actionPerformed(ActionEvent e) {
      doLoadCommand(editorPane, filename);
      }
      };
      JButton loadButton = new JButton(loadAction);
      panel.add(loadButton);

      content.add(panel, BorderLayout.SOUTH);

      doLoadCommand(editorPane, filename);

      frame.setSize(550, 550);
      frame.setVisible(true);
      }

      public static void doLoadCommand(JTextComponent textComponent, String filename)
      {
      FileReader reader = null;
      try
      {
      System.out.println("Loading");
      reader = new FileReader(filename);

      // Create empty HTMLDocument to read into
      HTMLEditorKit htmlKit = new HTMLEditorKit();
      HTMLDocument htmlDoc = (HTMLDocument) htmlKit
      .createDefaultDocument();
      // Create parser (javax.swing.text.html.parser.ParserDelegator)
      HTMLEditorKit.Parser parser = new ParserDelegator();
      // Get parser callback from document
      HTMLEditorKit.ParserCallback callback = htmlDoc.getReader(0);
      // Load it
      parser.parse(reader, callback, false);
      callback.flush();
      // Replace document
      textComponent.setDocument(htmlDoc);
      System.out.println("Loaded");

      } catch (Exception exception) {
      System.out.println("Load oops");
      exception.printStackTrace();
      } finally {
      if (reader != null) {
      try {
      reader.close();
      } catch (IOException ignoredException) {
      System.out.println("exception " + ignoredException);
      }
      }
      }
      }
      }
      ---------- END SOURCE ----------

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: