File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Hyperlinks in a single HTML help file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Hyperlinks in a single HTML help file" Watch "Hyperlinks in a single HTML help file" New topic
Author

Hyperlinks in a single HTML help file

Stephen Tracey
Greenhorn

Joined: Apr 08, 2004
Posts: 13
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

Joined: Mar 28, 2003
Posts: 11278
    
  59

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


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Stephen Tracey
Greenhorn

Joined: Apr 08, 2004
Posts: 13
Thank you so much! I didn't realize that I had to pitch the '#' from the string.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Apr 08, 2004
Posts: 13
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

Joined: Apr 08, 2004
Posts: 13
Doesn't work for my situation, Marcel. I'm sticking with Andrew's.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Mar 28, 2003
Posts: 11278
    
  59

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

Joined: Nov 22, 2008
Posts: 18944
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hyperlinks in a single HTML help file
 
Similar Threads
Mr.rahul congrats!! . pls. help me reg. JEditorPane
Question about generic swing JFrame structure
Send to printer
a file in your Jar, How do I access it in code?
Opening an html file