Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
288 views
in Technique[技术] by (71.8m points)

java - Show HTML file in JEditorPane

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

I am using JEditorPane control for it. It is showing the content of HTML file but not in the same format as originally in the actual HTML file.

JEditorPane does not support the object element. Rather than loading the object file its just showing ?.

Is there any other inbuilt control in Swing to browse the HTML file rather than 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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your best bet for more advanced HTML rendering in core Java is to use the JavaFX based WebView component as described in Adding HTML Content to JavaFX Applications. It supports HTML5, but I've not actually played with it, so I cannot say how well it renders HTML.

Note that Java FX is effectively an alternative to Swing, but AFAIU Java FX components can be embedded in Swing GUIs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...