Skip to content Skip to sidebar Skip to footer

How To Open Html File Having Another Extension In Jtextpane

I have a HTML file and I need to display it in JTextPane. editor.setPage('file:///' + new File('test-resources/test.html').getAbsoluteFile()); This works properly. It uses my modi

Solution 1:

One alternative is to use a JEditorPane and call JEditorPane.setContentType(String).

See setContentType(String) for details.

..For example if the type is specified as text/html; charset=EUC-JP the content will be loaded using the EditorKit registered for text/html and the Reader provided to the EditorKit to load unicode into the document will use the EUC-JP charset for translating to unicode..

Solution 2:

The solution has been found (see the post JEditorPane and custom editor kit):

publicvoidopenFile(String fileName)throws IOException {
    editor.setEditorKit(newModifiedHTMLEditorKit());
    ModifiedHTMLDocumentdoc= (ModifiedHTMLDocument)editor.getDocument();
    try {
        editor.getEditorKit().read(newFileReader(fileName), doc, 0);
    }
    catch (BadLocationException b) {
        thrownewIOException("Could not fill data into editor.", b);
    }
}

This is the proper technique.

Post a Comment for "How To Open Html File Having Another Extension In Jtextpane"