This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Opening an html file

 
Chris Masters
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 297
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 297
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 297
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 297
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you I got it working. It has been very educational.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic