How do i open a link in different browser in java swing??
I’ve read this article :
http://www.roseindia.net/tutorial/java/swing/openBrowser.html
This is opening in my default browser. But when I want to open in a different browser
it gives an error message: “Cannot run program “which”: CreateProcess error=2, The system cannot find the file specified
“
Generally speaking, to open a link in the user’s default browser you should really be using the more modern approach:
No need to mess about with working out what OS you are running on (as your linked example attempts to do). Far better to let
java.awt.Desktoptake care of finding an appropriate browser or application to open the URL (see the documentation for more details).There’s also a part of the API that gracefully handles permissions and ‘unusual’ OS setups. If there is the possibility that your code will run under a restricted security policy or on a platform that may not have a browser, then you can check up front rather than wait for the exception from the call to
browse.