我正在尝试在JEditor中呈现以下代码,这在Chrome和Mozile浏览器中工作正常但在EditorPane中没有。
<html><body>In the given figure, ABCD is a quadrilateral
in which BD = 10 cm, AL <SPAN>^</SPAN> BD,
CM <SPAN style=\"FONT-FAMILY:Symbol\">^</SPAN>
BD such that AL = 4 cm and CM = 6 cm.
Find the area of quadrilateral ABCD.<BR>
<IMG align=middle </body></html>
使用Unicode处理标签的工作正常,但我想使用标签显示它。
答案 0 :(得分:0)
此代码可以解决您的问题。
// make it read-only
editorPane.setEditable(false);
// add an html editor kit
HTMLEditorKit htmlkit = new HTMLEditorKit();
HTMLDocument htmlDoc = (HTMLDocument) htmlkit.createDefaultDocument();
editorPane.setEditorKit(htmlkit);
String htmlString = "<html><body>In the given figure, ABCD is a quadrilateral in which BD = 10 cm, AL <SPAN>^</SPAN> BD, CM <SPAN style=\\\"FONT-FAMILY:Symbol\\\">^</SPAN> BD such that AL = 4 cm and CM = 6 cm. Find the area of quadrilateral ABCD.<BR><IMG align=middle </body></html>";
Reader htmlStringReader = new StringReader(htmlString);
try {
htmlkit.read(htmlStringReader, htmlDoc, 0);
} catch (IOException e1) {
// TODO Auto-generated catch block
System.out.println(e1.getMessage());
e1.printStackTrace();
} catch (BadLocationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
editorPane.setEditorKit(htmlkit);
htmlDoc.putProperty("ZOOM_FACTOR", new Double(0.5));
editorPane.setDocument(htmlDoc);
最好的问候, 佩德罗·阿扎姆。