aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JEditPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JEditPane" Watch "JEditPane" New topic
Author

JEditPane

Daniel Harris
Greenhorn

Joined: Feb 22, 2009
Posts: 5
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

Joined: Sep 20, 2005
Posts: 862
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.

    bitguru blog
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: JEditPane