4

I am trying to render follwing code in JEditor Which is working fine in chrome and Mozile browser but not in 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>

Relacing tags with Unicode working fine but i want to display it using Tags.

StanislavL
  • 56,971
  • 9
  • 68
  • 98
naren_rana
  • 41
  • 2
  • As suggested [here](http://stackoverflow.com/q/13250061/230513), "Support for HTML in Swing Components is limited to 3.2…" – trashgod Jul 02 '14 at 13:06
  • 1
    @trashgod : Yes agree.But JavaFX support HTML-5 and this is not working in JavaFX too. – naren_rana Jul 03 '14 at 08:47

1 Answers1

0

This code may solve your question.

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

Best regards, Pedro Azzam.