Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hyperlinks in a single HTML help file

 
Stephen Tracey
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm sure this has been asked 1000 times, but I can't seem to find the answer.
I have a single HTML help file that I'm displaying in a JScrollPane ("helpPane") within a JEditorPane within a JFrame. The JFrame implements HyperlinkListener, but the editor doesn't jump to the bookmark. Help!

Thanks! This is my first post after 6 weeks of SCJD (this site is great), so please forgive me if I didn't insert the code in properly.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11854
185
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stephen,
Welcome to JavaRanch and this forum.
Try the following code (you should be able to see what it does):

By the way - the other option in my code allows me to use the Chain Of Command pattern to pass a HelpEvent to whatever class is providing the help pages, and retrieve a brand new page (from disk / database / web - who knows: it is totally abstracted ).
Regards, Andrew
 
Stephen Tracey
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much! I didn't realize that I had to pitch the '#' from the string.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stephen,
I strongly hesitate to argue with Andrew as he's usually right. However, I believe the following method achieves the desired behaviour (without Chain of Command) in a more elegant way.
Have I missed anything?
Regards,
Marcel
[ May 05, 2004: Message edited by: Marcel St�r ]
 
Stephen Tracey
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that I tried that first and it didn't work. Maybe that would work for jumping to a second file, whereas I'm jumping within the same HTML file? I'm hoping to keep it simple, a table of contents at the top then a "Back to top" link following each "chapter". Anyway, I'll gladly try your suggestion again out of curiosity.
 
Stephen Tracey
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't work for my situation, Marcel. I'm sticking with Andrew's.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephen,
My solution works for jumping within the same file using a simple HTML bookmark "#" as well as for external documents. At least on my PC it does ;-)
Regards,
Marcel
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11854
185
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marcel,
Originally posted by Marcel St�r:
I strongly hesitate to argue with Andrew as he's usually right.

Awww, you should always feel free to argue with me. I enjoy a good argument, especially if I learn something.
Originally posted by Marcel St�r:
However, I believe the following method achieves the desired behaviour (without Chain of Command) in a more elegant way.

Unfortunately I cannot get that to work on my system (Linux / Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02). The call to event.getUrl() always returns null!
The "chain of command" issue is totally separate from the problem with the hyperlinks - I left the section of code for getting the next page in the code snippet so that it was obvious that I was handling links to internal and external references differently, then added the comment about how I did that so that it might make more sense.
Regards, Andrew
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,
It's good to know my method doesn't work on your system. I will have see why this could be. In the meantime, here's the rest of the code.

And here comes a HTML snippet that works just fine.

Regards,
Marcel
[ May 06, 2004: Message edited by: Marcel St�r ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic