【问题标题】:Issue with Rendering Math symbol in JEditorPane在 JEditorPane 中渲染数学符号的问题
【发布时间】:2014-08-23 03:31:50
【问题描述】:

我正在尝试在 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 替换标签工作正常,但我想使用标签显示它。

【问题讨论】:

  • 正如here 建议的那样,“Swing 组件中对 HTML 的支持仅限于 3.2...”
  • @trashgod :是的,同意。但是 JavaFX 支持 HTML-5,这在 JavaFX 中也不起作用。

标签: java html swing fonts jeditorpane


【解决方案1】:

此代码可能会解决您的问题。

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

最好的问候, 佩德罗·阿扎姆。

【讨论】:

    猜你喜欢
    • 2011-01-23
    • 2020-10-29
    • 2015-07-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    • 2019-04-30
    • 1970-01-01
    • 2018-08-14
    相关资源
    最近更新 更多