Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String with URL

 
Marco Rossi
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 227
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that using java.awt.Desktop and it's browse method is a better solution than trusting on some OS specific technique.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic