• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JEditPane

 
Daniel Harris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me try to explain this...

I have a JEditPane. I also have a string of html code.



* the html is shortened.

What I want to do is use setText() to set the code of the edit pane.

If I do this, the picture doesnt show, it shows the small broken picture icon.
However, if I load the page via setPage() with a file, the picture shows. After I use setPage() I can then use setText() and the picture shows.

I'm guessing that something is being initialized in the edit pane when setPage() is called. Because after setPage(), the setText() calls work fine.

I would like to be able to do this without having to call setPage() first.

Heres a small example...




Thanks!


This question was also posted here: http://www.java-forums.org/awt-swing/16211-jeditpane.html
 
Brian Cole
Author
Ranch Hand
Posts: 903
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Sheets wrote:I have a JEditPane. I also have a string of html code. What I want to do is use setText() to set the code of the edit pane.

If I do this, the picture doesnt show, it shows the small broken picture icon.
However, if I load the page via setPage() with a file, the picture shows. After I use setPage() I can then use setText() and the picture shows.

I'm guessing that something is being initialized in the edit pane when setPage() is called. Because after setPage(), the setText() calls work fine.

I would like to be able to do this without having to call setPage() first.


Since your img src is a relative URL, you can't expect JEditorPane to know where to find it without help. Options:

  • use absolute img src URLs
  • put a <base> tag in your HTML string
  • set the Document.StreamDescriptionProperty on the editor pane's Document


  • The last two are described (if not especially well) in the javadoc for HTMLDocument.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic