JEditorPane中呈现数学符号的问题

4

我正在尝试在JEditor中呈现以下代码,这在Chrome和Firefox浏览器中运行良好,但在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工作得很好,但我希望使用标签显示它。

此处所建议,“Swing组件中对HTML的支持仅限于3.2版……” - trashgod
1
@trashgod:是的,同意。但是JavaFX支持HTML-5,而且在JavaFX中也无法工作。 - naren_rana
1个回答

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);

最好的祝福, Pedro Azzam。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接