Running URL in Java Swing Application

How to run url in user's default browser in Java Swing application code?

There is this Netbeans library, but the jar does not seem to contain the classes mentioned in the example.

And there seem to be many old examples .

But are there any solutions for killers?

+4
source share
3 answers

If you are working on JDK 1.6, you are java.awt.Desktop .

Desktop.getDesktop (). browse (new java.net.URI ("www.google.com"));

If you are working on an earlier JDK, I believe you can download the JDIC library . Or hack something together with spawning processes.

+6
source

To extend the answer, kdgregory , the Java Desktop API , available from Java 6, provides desktop integration with features such as launching default web browsers and email clients.

Launching a web browser can be achieved using the Desktop.browse method.

For example, running /fooobar.com / ... can be achieved as follows:

 Desktop.getDesktop().browse(new URI("http://qaru.site/")); 

Additional Information:

+2
source

You can look at BrowserLauncher , although the latest version of the JDK is trying to make it obsolete.

+1
source

All Articles