• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to capture a Hyperlink click without JEditorPane

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic