logo

Launching an external browser url from SWT

logo

In developing PasswordSafeSWT, I’ve never really been able to get URL launching working successfully (“Go to Password Safe Website” type stuff) on all platforms. I’ve toyed with BrowserLauncher (which seems to work great on Win32 and Linux but causes my OSX box all sorts of grief).

Well, after checking out some of the SWT newsgroups, the answer is much simpler than I thought. You can launch arbitrary programs using the Program class, and they launch with whatever app is associated with them (ie whatever is the default browser on the platform). So I just dropped the following line into my Action, and I was in business:

org.eclipse.swt.program.Program.launch("http://passwordsafe.sourceforge.net/");

I’m a raving fan-boy. I just love SWT….

9 Responses to “Launching an external browser url from SWT”

  1. Ciprian says:

    Thank you. I have been searching for days for this kind of stuff, in order to bring a Link widget in my SWT application to life.

    All I could find was Runtime.exec(), which starts the default browser for html files (try cmd /c file.html from a windows command prompt), but didn’t work for actual links.

    One more problem solved:) Thank you.

    Ciprian

  2. Glen Smith says:

    Glad I could help.

  3. Jens says:

    Love you man! Have been searching Google for something like this for like 20 minutes… gave up and started going thru my bookmarks instead (including your site) and here it is! Thanks!

  4. Glen Smith says:

    Good stuff. Enjoy.

  5. Anonymous says:

    A fantastic tip – I was about to go down the BrowserLauncher route until I found this. Unfortunately though, it doesn’t seem to work for me under KDE on Linux. My default browser there is Konqueror, and typing http://www.google.com into the Run box loads it just fine. Sadly, calling Program.launch does nothing on this platform (it assumedly returns false but I haven’t checked yet). The same code works perfectly under Windows XP (where it launches Firefox).

  6. Anonymous says:

    thanks a ton man ..see u wrote something 2 years back and it helped me a great deal today..thanks a ton

  7. Anon says:

    wow! what you wrote 5 years ago helped me today!
    Thanks!!

  8. Will Bath - fellow CJugger says:

    Hahaha… same, thanks Glen!

  9. student says:

    thanks!!
    it was very helpful to me!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

logo
logo
Powered by WordPress | Designed by Elegant Themes