tags:

views:

706

answers:

1

I have a JLabel which has an e-mail address in it. I used HTML formatting on the JLabel, so it appears as a link. However, you are not able to click the link. In fact, you cannot select any of the text in the label. Is there a property that I can set on the JLabel to allow the user to at least select the text of the e-mail, and preferably to click on the e-mail address the way they would on a webpage?

My code for my JLabel is essentially:

JLabel l = new JLabel("<html><a href=\"mailto:[email protected]\">[email protected]</a>");
+3  A: 

The default JLabel doesn't allow you to do this. If you really want to use a JLabel, you could add a mouse listener to it to capture clicks and react to them. Another way would be to use a non-editable JEditorPane and call addHyperlinkListener on it to add your HyperlinkListener.

bdumitriu