wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes How to capture a Hyperlink click without JEditorPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to capture a Hyperlink click without JEditorPane" Watch "How to capture a Hyperlink click without JEditorPane" New topic
Author

How to capture a Hyperlink click without JEditorPane

Jes Sie
Ranch Hand

Joined: Jul 24, 2001
Posts: 188
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


Thank you.<br /> <br />- Jess Sie<br /> <a href="mailto:jess@see-consulting.com" rel="nofollow">jess@see-consulting.com</a>
Matt Hansen
Ranch Hand

Joined: Jul 31, 2001
Posts: 34
You just need to add a Mouse Listener to the JLabel to catch the click.
Example:
Jes Sie
Ranch Hand

Joined: Jul 24, 2001
Posts: 188
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

Joined: Aug 23, 2001
Posts: 23
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.

 
jQuery in Action, 2nd edition
 
subject: How to capture a Hyperlink click without JEditorPane
 
Similar Threads
Oracle develompnet env for UML
Customed JLabel and Customed JButton
Capture Hyperlink click in JButton or JLabel
JFrame or customed JDialog or ?
IBM question - Mortgage