The moose likes Java in General and the fly likes String with URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "String with URL" Watch "String with URL" New topic

String with URL

Marco Rossi
Ranch Hand

Joined: Jul 01, 2011
Posts: 30
Hi all,

I have a String, for example:

String website = ""

I would like that, inside a SWT MessageBox (but in any other place of my application) by clicking on the String the browser opens and loads the it possible?
Aditya Jha
Ranch Hand

Joined: Aug 25, 2003
Posts: 227

Not so sure about SWT, but in Swing I would do something like this:

Note that the exact command to run (in exec()) will be OS specific. Usually, we use OS-specific property-files to make the code portable.

I'm not sure if this automatically provides the functionality of mouse cursor turning into the 'Hand' cursor on moving over the link. But if not, take it as an exercise and try to implement it.

Hope this helps!
Rob Spoor

Joined: Oct 27, 2005
Posts: 20271

I think that using java.awt.Desktop and it's browse method is a better solution than trusting on some OS specific technique.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: String with URL
It's not a secret anymore!