-
Bug
-
Resolution: Fixed
-
P4
-
1.4.0
-
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.
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.
- duplicates
-
JDK-4671653 JTextPane.insertIcon doesn't insert image in HTML docs
-
- Closed
-