Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to capture a Hyperlink click without JEditorPane

 
Jes Sie
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I've got a a few objects and all of them has got a HTML based description. Each description has got Hyperlink which actually has a link to represent an ID of the object.
Question: How can I capture a Hyperlink click on these.
I did attempt to use JLabel and JButton HTML capabilities, but none of them seems to work for Hyperlink tag.
I did have a look at how JEditorPane works with "implements HyperlinkListener"...but I'm not looking at displaying a real URL but just want to capture a Hyperlink click.
Pls help.
Example:
String htmlText = "<html>I love a person";
JLabel lb1 = new JLabel(htmlText);
// or
JButton b1 = new JButton(htmlText);
// but then what?

------------------
Thank you.
- Simon See
simon-ivy@usa.net
-after office hours-
necro-mani-cide
 
Matt Hansen
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You just need to add a Mouse Listener to the JLabel to catch the click.
Example:
 
Jes Sie
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Matt Hansen:
[B]You just need to add a Mouse Listener to the JLabel to catch the click.
Example:
[/B]

Heh, thanks Matt for replying.
I understand what you're saying, but my JLabel only has certain portion is meant to be clickable...like the portion with the Hyperlink. YOur code above tells me the whole JLabel is clickable.
Am I missing something here....I'm pretty new at Swing
------------------
Thank you.
- Simon See
simon-ivy@usa.net
-after office hours-
necro-mani-cide
 
Jeff Chang
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simon
Maybe you can use two strings like:
String htmlText1 = "I love a ;
String htmlText2 = "person";
...
then make only the 2nd string link to the URL.
Good luck.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic