View Full Version : Java - Launch html Document
VegetaPunk
Feb 4, 2006, 02:53 AM
Im using JBuilder to make a java application.
In this application I want to add a help button that when you press it launches a help.html document, that I have made, using the systems defualt browser. How do I launch a document in java?
robbieduncan
Feb 4, 2006, 05:13 AM
I don't think it's possible in pure java as the method for doing that will be OS dependant. On OSX you would do it via NSWorkspace (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Java/Classes/NSWorkspace.html) using the openURL (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Java/Classes/NSWorkspace.html#//apple_ref/java/instm/com.apple.cocoa.application.NSWorkspace/openURL) method. You will need to look at other solutions for other platforms.
iJed
Feb 4, 2006, 05:49 AM
Im using JBuilder to make a java application.
In this application I want to add a help button that when you press it launches a help.html document, that I have made, using the systems defualt browser. How do I launch a document in java?
I believe you could use Runtime (http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html).exec("/usr/bin/open " + filePath).
You may not need to use the open command but I'm not sure as I've never tried this before. Also remember that open is Mac OS X specific so it will not be a good cross platform solution.
gekko513
Feb 4, 2006, 10:00 AM
Im using JBuilder to make a java application.
In this application I want to add a help button that when you press it launches a help.html document, that I have made, using the systems defualt browser. How do I launch a document in java?
This piece of code looks very promising. (http://www.centerkey.com/java/browser/) (The web designer's sense of usability/readability isn't quite as promising.)
ryan
Feb 5, 2006, 12:32 AM
Depending on the complexity of the HTML you're looking to display I'd recommend looking at Java's JEditorPane (http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JEditorPane.html).
jalagl
Feb 5, 2006, 12:42 AM
I believe you could use Runtime (http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html).exec("/usr/bin/open " + filePath).
You may not need to use the open command but I'm not sure as I've never tried this before. Also remember that open is Mac OS X specific so it will not be a good cross platform solution.
I've used this before on Windows, and it launches the default browser (it is the same functionality as if you double-clicked the html file.
VegetaPunk
Feb 6, 2006, 05:10 PM
TY for all the help guys!
I used the runtime and it works on the mac now I just need to test it on my pc! thanks again!
VegetaPunk
Feb 6, 2006, 05:32 PM
=( it didnt work with windows is there another path I need to use besides "/usr/bin/open" ?
thanks in advance
VegetaPunk
Feb 6, 2006, 05:43 PM
"cmd /c" worked for me (using win2k) =)
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.