public void read(InputStream in, Object document) throws IOException
in
is the stream from which the HTML will be read.
document
should be an instance of
javax.swing.text.html.HTMLDocument
. (You can use another type, but
if you do the JEditorPane
will treat the stream as plain text
rather than HTML.)
Although you could use the HTMLDocument()
noargs
constructor to create the HTMLDocument
object, the document it
creates is missing a lot of style details.
Instead let a
javax.swing.text.html.HTMLEditorKit
create the document for you.
You get an EditorKit htmlKit = jep.getEditorKitForContentType("text/html");HTMLEditorKit
by passing the MIME type you want to edit
(text/html in this case) to the JEditorPane
getEditorKitForContentType()
method like this:
Finally, before reading from the stream you have to use the
jep.setEditorKit(htmlKit);JEditorPane
's setEditorKit()
method to install a
javax.swing.text.html.HTMLEditorKit
. For example,