【问题标题】:How to resolve java.net.MalformedURLException: no protocol:?如何解决 java.net.MalformedURLException:没有协议:?
【发布时间】:2014-05-24 10:17:58
【问题描述】:

代码:

public SelectedMap() {
    initComponents();
    editorMap_pn.setEditable(false);
    try {
        editorMap_pn.setPage("<html><body>Hello</body></html>");
    } catch (IOException ex) {
        Logger.getLogger(SelectedMap.class.getName()).log(Level.SEVERE, null, ex);
    }
}

输出:

Tracker.UI.SelectedMap <init>
SEVERE: null
java.net.MalformedURLException: no protocol: <html><body>Hello</body></html>
    at java.net.URL.<init>(URL.java:583)
    at java.net.URL.<init>(URL.java:480)
    at java.net.URL.<init>(URL.java:429)
    at javax.swing.JEditorPane.setPage(JEditorPane.java:882)
    at Tracker.UI.SelectedMap.<init>(SelectedMap.java:33)

我想在 Java 应用程序中显示 HTML 页面,而不是 URL。 我想输入 HTML 代码作为 setter 的输入并显示 Web 输出。

【问题讨论】:

    标签: java html swing url jeditorpane


    【解决方案1】:

    documentation for JEditorPane.setPage(String) 告诉我们:

    设置当前显示的URL

    所以:

    editorMap_pn.setPage("<html><body>Hello</body></html>");
    

    应该是:

    editorMap_pn.setText("<html><body>Hello</body></html>");
    

    请注意,您可能还需要设置内容类型和不可编辑。

    【讨论】:

      猜你喜欢
      • 2010-12-14
      • 1970-01-01
      • 1970-01-01
      • 2022-08-05
      • 2014-05-26
      • 2012-03-13
      • 2014-02-24
      • 2011-11-22
      • 2018-11-08
      相关资源
      最近更新 更多