在java swing中浏览html文件

时间:2012-09-22 10:59:51

标签: java swing html-parsing

我以Java swing形式显示Html文件数据。内容正在显示但有些格式受到干扰。正在显示图像,但格式化受到干扰。 和超链接不起作用你可以建议我的代码,我使用下面的代码。 setContentType方法

有问题
    File htmlFile = new File("e:/test/help4t.htm");
             htmlPane = new JEditorPane();
            htmlPane.setContentType("text/html");
        htmlPane.setPage(htmlFile.toURI().toURL());
         //URL url= new URL("http://www.lawcrux.com");


       //  htmlPane.setPage(url);
         htmlPane.addHyperlinkListener(this);

        JScrollPane jsp= new JScrollPane(htmlPane);

                cp.add(jsp);
        jsp.setBounds(750, 50, 600, 600);  


        } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, "exception is" + ex);
        }

请帮助

问候

1 个答案:

答案 0 :(得分:2)

为什么不使用Jsoup,因为它为提取和操作数据提供了一个非常方便的API。

请参阅此链接:

http://jsoup.org/