jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes open Browser from java application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "open Browser from java application" Watch "open Browser from java application" New topic

open Browser from java application

YuenLian Wu
Ranch Hand

Joined: Nov 16, 2005
Posts: 73
Dear all,

I am new to Java, and I hope you can answer my stupid question. I want to open a browser with URL specified from a Java application window(GUI with JFC/Swing). How can I implement that ? e.g There is a JButton @ the GUI form, and once I click the button, then the IE will be opened and forward to the site that I specified @ the GUI form.

Please help me out

Myraid Thanks

marc weber

Joined: Aug 31, 2004
Posts: 11343

Look at the java.lang.Runtime class. But keep in mind that not everyone uses (or even has) Microsoft IE.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
marc weber

Joined: Aug 31, 2004
Posts: 11343

Hmmm... Apparently, Java 6 will introduce a new Desktop API that will launch the default browser or email client. (Nice!)

In the meantime, I just found this code for a decent platform-independent approach. I haven't tried it myself, so let us know how this works if you use it.

(PS: I found these by searching on "java default browser".)
[ May 21, 2006: Message edited by: marc weber ]
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
The class Marc mentioned could be combined with this one to get something decent, I think.
I agree. Here's the link: http://aspose.com/file-tools
subject: open Browser from java application
It's not a secret anymore!