Two Laptop Bag*
The moose likes Swing / AWT / SWT and the fly likes Urgent help required for JEditorPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Urgent help required for JEditorPane" Watch "Urgent help required for JEditorPane" New topic
Author

Urgent help required for JEditorPane

Garry Kalra
Ranch Hand

Joined: May 25, 2001
Posts: 111
Pls help me regarding how i can show a html file within a jeditorpane. The application is packaged as a jar file and the html file is stored in a directory name htmlfiles under the jar.
I am having trouble doing that as it is used as a help system for the application. I think that the problem lies in the url stuff. What url should i give for a html file within the jar file.
Any help will be greatly appreciated.
Garry
Laudney Ren
Ranch Hand

Joined: Jan 06, 2002
Posts: 111
Your instinct is GREAT!
The problem lies in the URL.
First, there is JarURLConnettion:
pubic abstract class JarURLConnection extends URLConnection // Java 1.2
Second, we need a "jar URL", which is constructed in the following way:
suppose you have a URL:
http://ttcplinux.sourceforge.net/java/network.jar,
and in the .jar, you want the file:
com/arpabox/net/Ping.class
The corresponding "jar URL" is:
jar:http://ttcplinux.sourceforge.net/java/network.jar!/com/arpabox/net/Ping.class
Get it??
Another example:
URL: ftp:///D%7d/java/network.jar
file: com/arpabox/net/Ping.class
Jar URL: jar:ftp://D%7d/java/network.jar!/com/arpabox/net/Ping.class
So, here, you now how to construct the "Jar URL".
Then, use it to read the html file as follows:
try {
URL u = new URL("jar:http://ttcplinux.sourceforge.net/java/network.jar!/com/arpabox/net/index.html");
URLConnection uc = u.openConnection();
InputStream in = uc.getInputStream();
Reader r = new InputStreamReader(in);
int c;
while ((c = r.read()) != -1) {
System.out.print((char)c);
}
}
catch (IOException e) {
system.err.println(e);
}


" Veni, vidi, vici "<br />" I came, I saw, I conquered "
Laudney Ren
Ranch Hand

Joined: Jan 06, 2002
Posts: 111
In fact, JarURLConnection has a lot of methods which you may find in the API.
You can construct like this:
URL u = new URL("a jar URL goes here");
JarURLConnection juc = u.openConnection();
Garry Kalra
Ranch Hand

Joined: May 25, 2001
Posts: 111
Thanks a lot for the rely.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Urgent help required for JEditorPane
 
Similar Threads
Urgent help required for JEditorPane
Packaging questions
class.getResource Problem
JAR packaging problem
Help Menu