Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make hyperlink to openup in browser and e-mail link in e-mail client

 
Raja Sekhara
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one requirement to put a website address and e-mail address in a dialog, showing them like hyperlinks.

Say like adding hyperlink in JLabel.
1. new JLabel("<html><A href="+"http://www.javaranch.com" +">"+"http://www.javaranch.com"+ "</A></html>");

2. new JLabel("<html><A href="+"support@somemail.com" +">"+"support@somemail.com"+ "</A></html>");

In 1) when we click on hyper link it should open up website in clients default browser.
I would be able to do this by adding label to a button or just hyperlink text to button and writing code in actionPerformed method.

Is there any other easy way in API.

In 2) When clicked on e-mail hyperlink, it should open up in e-mail client, showing e-mail in to field of e-mail client.
For example, it should open up outlook and it should be like new message with to field filled with "support@somemail.com ".

Hint: Goto START->RUN-> type in run field "msimn.exe support@somemail.com"
This works if you have outlook installed in your system. But it opens outlook, not the new message with TO field filled with e-mail address mentioned.

I don't know how to implement this in code for my swing application.

Can any body know how to do this?

Thanks in advance.
 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raja,

Check out the javax.swing.event.HyperlinkEvent class. It will give you a URL you can use to execute a command on the command line.

Darrin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic