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

JEditorPane inserts chars into <head> section instead of <body> in HTML doc

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 1.4.2
    • client-libs
    • beta
    • x86
    • windows_2000, windows_xp



      Name: gm110360 Date: 05/06/2004


      FULL PRODUCT VERSION :
      java version "1.4.2_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
      Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [verziM-^OÀ»szM-^OÀ»m: 5.1.2600]
      (Hungarian WinXP)

      A DESCRIPTION OF THE PROBLEM :
      There is a mystical "0th position" in the JEditorPane before the first
      visible character when initialized with static text. Home or CTRL+Home may be used to get at this location.
      Insertion is possible at this location, which can be tracked but actually
      not visible. Debugging shows that the input inserted at this location actually goes into the header section of the embedded HTMLDocument.
      Once pushing a Backspace in the first visible position, this "mystical insertion point" disappears and functionality becomes normal.
      (If making a "Paste" action at this location, even an Exception is thrown!)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the provided code, then push "Home" or "CTRL+Home" and type a letter.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The letter should appear as the first character in the editor pane's content area and should be inserted as the first character of the <body> section of the document.
      ACTUAL -
      Watching the debug info displayed by the program it can be seen that the letter you have typed has been inserted into the <head> section of the JEditorPane's HTML document. It is invisible in the editor pane's content area.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.JEditorPane;
      import javax.swing.JFrame;
      import javax.swing.text.*;
      import javax.swing.text.html.HTMLDocument;

      public class JEditorPane_bugdemo {
        static JEditorPane editorPane;

        /* A custom document filter class for debugging. */
        public static class MyDocumentFilter extends DocumentFilter {
          public MyDocumentFilter() { }

          public void insertString(FilterBypass fb, int offs, String str, AttributeSet a)
              throws BadLocationException {
            System.out.println("insertString: offset: " + offs + ", string: " + str);
            super.insertString(fb, offs, str, a);
            System.out.println("new contents: \"" + editorPane.getText() + "\"");
          }

          public void remove(DocumentFilter.FilterBypass fb, int offs, int length)
              throws BadLocationException {
            System.out.println("remove: offset: " + offs + ", length: " + length);
            super.remove(fb, offs, length);
            System.out.println("new contents: \"" + editorPane.getText() + "\"");
          }

          public void replace(FilterBypass fb, int offs, int length, String str, AttributeSet a)
              throws BadLocationException {
            System.out.println("replace: offset: " + offs + ", length: " + length + ", new string: " + str);
            super.replace(fb, offs, length, str, a);
            System.out.println("new contents: \"" + editorPane.getText() + "\"");
          }
        }

        public static void main(String[] args) {
          editorPane = new JEditorPane();
          editorPane.setContentType("text/html");
          editorPane.setEditable(true);
          ( (HTMLDocument) editorPane.getDocument()).setDocumentFilter(new MyDocumentFilter());
          editorPane.setText("<html><body>This is a JEditorPane.</body></html>");

          JFrame frame = new JFrame("The mystical 0th position in JEditorPane");
          frame.getContentPane().add(editorPane);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.show();
        }

      }

      ---------- END SOURCE ----------
      (Incident Review ID: 246030)
      ======================================================================

            alexp Alexander Potochkin (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: