File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JEditorPane HTML Anchor Links Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JEditorPane HTML Anchor Links" Watch "JEditorPane HTML Anchor Links" New topic

JEditorPane HTML Anchor Links

David Reck
Ranch Hand

Joined: May 25, 2001
Posts: 37
I have loaded an HTML file in a JEditorPane as a systems online help. The file has some links that are anchors to places lower in the file. How do I make these links work. I have tried using a HyperlinkListener but am not having much luck getting it to work like anchors work in a browser.
Ranch Hand

Joined: Jun 21, 2001
Posts: 57
try out !!!
jEditorPane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent hev) {
try {
if (hev.getEventType == HyperlinkEventType.ACTIVATED)
catch (IOException e) {
// Exceptions thrown...............

Ranch Hand

Joined: Jun 21, 2001
Posts: 57

Add a hyperlinkListner to your JEditorPane via addHyperlinkListener().
Define a hyperlinkUpdate() method as required when adding this listener.
I agree. Here's the link:
subject: JEditorPane HTML Anchor Links
jQuery in Action, 3rd edition