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

HTMLEditorKit.create() cannot handle some element types.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 1.4.0
    • client-libs
    • beta
    • generic, x86
    • generic, windows_98

      HTMLEditorKit.create() cannot handle element types that do not set the name attribute using StyleConstants.NameAttribute. As a result, methods like JTextPane.insertComponent() do not work properly with an HTMLEditorKit.

      The problem is that AbstractDocument and StyledEditorKit use AbstractDocument.ElementNameAttribute to represent the element name and HTMLDocument and HTMLEditorKit use StyleConstants.NameAttribute.

      When HTMLEditorKit then calls getAttribute(StyleConstants.NameAttribute) and the name is not defined, the attribute resolves upwards to the parent until if finds something (ie. the wrong element type).

      You can see this behavior with the attached test case. Compile and run ComponentTest.java. Hitting the button on top should insert components into the JTextPane. Instead, blank space is inserted. Hitting the button at the bottom brings up a tree showing the view structure. Notice that javax.swing.text.html.ParagraphViews are being created where the ComponentViews should be.

      Additional note:
      I suspect the fix to this will involve changes to HTMLEditorKit.create() so I am making a note of something else that should change there. This is not causing the bad behavior described in the bug report but may when the bug is fixed.

      Lines 1153 and 1154 read:

      } else if (nm.equals(AbstractDocument.ParagraphElementName)) {
          return new ParagraphView(elem);
      }

      I beleive this should create a new java.swing.text.ParagraphView instead.

            idk Igor Kushnirskiy (Inactive)
            shickeysunw Shannon Hickey (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: