Pregunta

Code:

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);
    }
}

Output:

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)

I want to show HTML page in Java application but not a URL. I want to input HTML code as an input to setter and show the web output.

¿Fue útil?

Solución

The documentation for JEditorPane.setPage(String) tells us:

Sets the current URL being displayed.

So:

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

Should be:

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

Note that you might also need to set a content type and non-editable.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top