wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes displaying HTML in a JEditorPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "displaying HTML in a JEditorPane" Watch "displaying HTML in a JEditorPane" New topic
Author

displaying HTML in a JEditorPane

Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
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

Joined: Mar 25, 2000
Posts: 230
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

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Mar 25, 2000
Posts: 230
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

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Mar 25, 2000
Posts: 230
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

Joined: May 18, 2000
Posts: 52
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

Joined: Nov 22, 2008
Posts: 18944
Thanks,Frank. I got it at last.
Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
>Thanks,Frank. I got it at last.
Glad I could help!
Have fun,
Frank
Anamika Singh
Ranch Hand

Joined: Jun 28, 2002
Posts: 66
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: displaying HTML in a JEditorPane
 
Similar Threads
JEditorPane - following links within locally created HTML
Open a Web Page inside a jDesktopPane
create a html help menu
InputStream from JEditorPane
display web page