• 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

clickable text

 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the best way to implement clickable text in java?
 
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you need to create this hyperlink in an Applet or in an application?
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I assume that you are referring to something similar to clicking the mouse on a link (in html).
You can use a javax.swing.JLabel and add a MouseListener to the Label.
Ashwin.
 
Joseph Russell
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually it would be in an application. Very similiar to JQ+ when you can click on a question that's wrong and it takes you to that window.
Thanks Ashwin I'll check it out.
joe
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joseph,
Although it certainly is possible to detect a click on a JLabel, if you want to use a "true" hyperlink, you should consider using a JEditorPane and calling its addHyperlinkListener() method. That method allows you to register a listener that will be notified of events related to the hyperlink, such as when the cursor moves over and away from it, and when it's "activated" (i.e., when the user has clicked on the link). Although you can do the same things with a JLabel, I suspect that you'd find JEditorPane a more convenient choice, at least if you want your "clickable text" to work the way most users expect a hyperlink to work.
------------------
Brett Spell
Author, Professional Java Programming
reply
    Bookmark Topic Watch Topic
  • New Topic