正确显示JEditorPane java上的网站

时间:2016-08-20 17:46:18

标签: java html css jeditorpane

我将我的程序中的JEditorPane返回到一个网站,比如google示例, 但它没有正确显示页面,没有它的CSS风格。  呃, 检查我的代码:

JEditorPane editorPane = new JEditorPane() {
        public boolean getScrollableTracksViewportWidth() {
            return true;
        }};

    editorPane.setEditable(false);

    HTMLEditorKit kit = new HTMLEditorKit();
    Document doc = kit.createDefaultDocument();
    editorPane.setDocument(doc);
    editorPane.setEditorKit(kit);

    try {
        editorPane.setContentType("text/html");
        editorPane.setPage("http://www.google.fr/");
    }catch (IOException e) {
        editorPane.setContentType("text/html");
        editorPane.setText("<html>We can't load this page</html>"
                + e.getMessage() + " ");
    } 

    editorPane.setBounds(295, 265, 491, 474);
    editorPane.setBorder(new LineBorder(new Color(0, 0, 0)));

    pan.add(editorPane);

我只是想在java组件中显示一个网站来显示新闻和其他信息, 有人可以帮我吗?

1 个答案:

答案 0 :(得分:1)

JEditorPane仅支持基本HTML。

要获得完全支持,您可以使用系统的默认浏览器。查看How to Integrate with the Desktop Class上Swing教程中的部分,了解使用&#34; BROWSE&#34;的工作示例。功能。