Show HTML file in JEditorPane

I am working on a Swing application in which I have to display HTML files.

I use the JEditorPane control for this. It displays the contents of the HTML file, but not in the same format as the original in the actual HTML file.

JEditorPane does not support the object element. Instead of loading an object file, does it just show ? .

Is there any other built-in control in Swing to view the HTML file, and not JEditorPane ?

I am using the following code:

 JEditorPane HtmlPane= new JEditorPane(); File file1= new File("path of the file"); HtmlPane.setContentType("text/html"); HtmlPane.setEditable(false); HtmlPane.setPage(file1.toURI().toURL()); JScrollPane jsp=new JScrollPane(HtmlPane); 
+4
source share
3 answers

It is best to use the JavaFX-based WebView component for more advanced HTML rendering in core Java, as described in Adding HTML Content to JavaFX Applications . It supports HTML5, but I actually did not play with it, so I can’t say how well it renders HTML.

Please note that Java FX is actually an alternative to Swing, but AFAIU Java FX components can be integrated into Swing GUIs.

+3
source

HTML support in Swing components is limited to 3.2 , preceding the <object> . You might be able to use the HyperlinkListener illustrated here in conjunction with Desktop#browse() . See also this example .

+2
source

To display html content from a local file, the local file extension must be ".html". The JEditor panel will display "content.html" but will not display "content.txt".

-1
source

Source: https://habr.com/ru/post/1444330/


All Articles