• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

displaying HTML in a JEditorPane

 
Frank Hale
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I display an HTML page in a JEditorPane which lives on my hard drive? I don't know how to pass the path of the page in a platform independent way. I know I can pass it a URL but what would the URL be? Everything I've tried just gives me an empty JEditorPane everytime.
Thanks,
Frank
 
Frank Hale
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out. Here is the code which will load an HTML page into a editorpane when passed a html file on your hard drive:
public void showPage(String page)
{
URL pageURL = getClass().getResource(page);
try
{
editorpane.setPage(pageURL);
}
catch (java.io.IOException ioe)
{
System.out.println("IOExecption while loading page.");
}
}
Frank
[This message has been edited by Frank Hale (edited May 29, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please tell me how you define the String page here? I tried to pass a path or a file name, but it always gives me an Invalid URL error.
Thank you.
 
Frank Hale
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It definitely works I am using it.
Here is how I do it:
showPage("help\\toc.html");
Where help is a directory with my html files and toc.html is the html file I want to show.
Hope this helps.
Frank

[This message has been edited by Frank Hale (edited June 08, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried in your way, but it still doesn't work. May I ask what ojbect you use to call showPage(String) method?
Thanks.
 
Frank Hale
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the complete code which I am using. Note that its not finished and only illustrates how to load a HTML in a JEditorPane and also react to links inside the HTML.
Here is the complete code:
 
Greg Whelan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is a slight variant on displaying an HTML page from disk... How can you get an JEditorPane to display an HTMLDocument which you have constructed?
The setPage method only supports URLs (which does offer one means of achieving the desired functionality: write the document to disk and then read it back in, but that is obviously a very inelegant hack, and simply won't work for unsigned applets)
If I use the setText method the JEditorPane will display the specified HTML document unrendered (ie. it will show all the tags, it does not retrieve images, etc.)
Any tips?
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,Frank. I got it at last.
 
Frank Hale
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>Thanks,Frank. I got it at last.
Glad I could help!
Have fun,
Frank
 
Anamika Singh
Ranch Hand
Posts: 67
IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Greg Whelan:
My question is a slight variant on displaying an HTML page from disk... How can you get an JEditorPane to display an HTMLDocument which you have constructed?
The setPage method only supports URLs (which does offer one means of achieving the desired functionality: write the document to disk and then read it back in, but that is obviously a very inelegant hack, and simply won't work for unsigned applets)
If I use the setText method the JEditorPane will display the specified HTML document unrendered (ie. it will show all the tags, it does not retrieve images, etc.)
Any tips?


I faced the same problem using HTML .u can try setPage("file:/c:/jdocs/pg.html") for a file named pg.html in ur c drive in jdocs folder. This worked fine with me .
[ June 28, 2002: Message edited by: Anamika Singh ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic