File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Opening an html file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Opening an html file" Watch "Opening an html file" New topic
Author

Opening an html file

Chris Masters
Greenhorn

Joined: Apr 13, 2001
Posts: 21
I am working on a java application. Previously it was an applet I have managed to modify to function as an applet. My current problem is that the help files were written into HTML and that they were accessed using the getDocument() function associated with the applet class. Currently I'm using the JFrame control in place of the applet and it does not seem to have an equivalent method. Do you have any suggestions?
Michael Hildner
Ranch Hand

Joined: Oct 13, 2000
Posts: 297
You can use a JEditorPane to display HTML in a java app. The tutorial has some explanations.
[This message has been edited by Michael Hildner (edited May 02, 2001).]
Chris Masters
Greenhorn

Joined: Apr 13, 2001
Posts: 21
I've used the JeditorPane but it generates an error when opening. My code is as follows:
shortname = httpFileName;
setMessage("Invoking HTML file: "+shortname);
try {
JEditorPane htmlPane = new JEditorPane(shortname);
htmlPane.setEditable(false);
this.add(new JScrollPane(htmlPane));
}
catch(IOException ioe){ System.err.println("Error displaying " + httpFileName);}
setCursor(Default_Cursor);
After going through debugging I've confirmed that it does excute the JEditorPane but then it throws the exception. I have confirmed the files are there. Any ideas?
Michael Hildner
Ranch Hand

Joined: Oct 13, 2000
Posts: 297
Here's some code I once used, hope it helps. The one thing I see is not setting the content type:

If you are still getting an Exception, please post it.
[This message has been edited by Michael Hildner (edited May 02, 2001).]
Chris Masters
Greenhorn

Joined: Apr 13, 2001
Posts: 21
Thank you for the sample code witha few changes and by adding an addtional frame to the application the simple browser now works. My new problem is that it displays the html page however the links and the frames do not work. I assume I'll have to add a HyperlinkListner to fix the links but how to I go about gettin it to recognize the frames?
It occurs to me it might be easier to simply launch explorer from the application. Unfortunately I'm clueless on how to do that. If you can answer either of these questions Id apprecaite. Take care
Michael Hildner
Ranch Hand

Joined: Oct 13, 2000
Posts: 297
I'm not sure if JEditorPane even supports HTML frames. Took a quick look and couldn't find anything. To launch an html from Java (Win32) you can use:
Runtime.getRuntime().exec(cmd);
Where cmd might be "start help.html" - open default browser, or
"iexplore" to launch ie (iexplore.exe has to be in user's %path%)
Chris Masters
Greenhorn

Joined: Apr 13, 2001
Posts: 21
I'm sure you're tired of the newbie questions but hopefully this will be my last. I tried putting the directory name of the html page and it doesn't work. All my documentation on the Runtime class is pretty thin do you want the rules are regarding how you pass a commandline to the runtime class are?
If I wanted to open a html page with the default directory what would that look like?
Michael Hildner
Ranch Hand

Joined: Oct 13, 2000
Posts: 297
This thread I think has exactly what you want. If you search JavaRanch for 'getRuntime', you'll also find a bunch of samples.
Chris Masters
Greenhorn

Joined: Apr 13, 2001
Posts: 21
Thank you I got it working. It has been very educational.
 
wood burning stoves
 
subject: Opening an html file