This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes String with URL Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "String with URL" Watch "String with URL" New topic
Author

String with URL

Marco Rossi
Ranch Hand

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

I have a String, for example:

String website = "http://www.coderanch.com"

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 website...is 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
Sheriff

Joined: Oct 27, 2005
Posts: 19216

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


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: String with URL
 
Similar Threads
Removing Characters from String
How to know a variable is an array or not in Javascript
Parsing a string with a e(circumflex) character
Regex Woes
PMD tool for Bug Tracking