在java中浏览html文件[重复]

时间:2021-06-13 20:09:18

Possible Duplicate:
display HTML page the same in Java forms

可能重复:在Java表单中显示相同的HTML页面

I want to display a HTML file in Java Swing application. I am using the following code, it displays the specified URL web page but I want to display a static HTML page stored on a particular location eg D:\\new folder\test.html. How is it possible? Is there any other useful tool in Swing than JEditorpane?

我想在Java Swing应用程序中显示一个HTML文件。我使用以下代码,它显示指定的URL网页,但我想显示存储在特定位置的静态HTML页面,例如D:\\ new folder \ test.html。这怎么可能?在Swing中还有其他有用的工具而不是JEditorpane吗?

I am using the following code

我使用以下代码

try {
    URL url= new URL("http://www.lawcrux.com");
    htmlPane = new JEditorPane();
    htmlPane.setContentType("text/html");
    htmlPane.setPage(url);
    htmlPane.addHyperlinkListener(this);

    JScrollPane jsp= new JScrollPane(htmlPane);

    cp.add(jsp);
    jsp.setBounds(750, 50, 600, 600);  
} catch(Exception ex) {} 

1 个解决方案

#1


2  

Try this:

File htmlFile = new File("c:/web.html");
htmlPane.setPage(htmlFile.toURI().toURL());

#1


2  

Try this:

File htmlFile = new File("c:/web.html");
htmlPane.setPage(htmlFile.toURI().toURL());