• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading HTML document into JEditorPane

 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to load a simple HTML document from disk into a JEditorPane. To be honest this whole API is confusing me somewhat, but it seems the right way to do this is to use the read method of the EditorKit. Below is the code I have:

This gives a javax.swing.text.ChangedCharSetException at the kit.read line and I have no idea why! Can somebody assist, or provide a better way to read HTML from disk into a JEditorPane? The reason I wanted to do this was to test the extend of the support for CSS in JEditorPane.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the 'setPage' method works okay. The 'ChangedCharSetException' is mentioned in the JEditorPane api toward the end of the discussion section. In the app below I tried to experiment with recovering from a failed read attempt. Java does not seem to know what to do with the meta statement in the html file. Maybe it's too new for html 3.2 of isn't needed/used. Both read methods work okay if the meta statement is omitted.

edited to remove smileys
[ August 20, 2005: Message edited by: Craig Wood ]
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Craig, that really helped. Yes, one of the problems was that my HTML (generated by Dreamweaver) was loaded with metadata. Thanks again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!