wood burning stoves*
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
Author

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.
David
Javaoops
Ranch Hand

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

Javaoops
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.
 
Consider Paul's rocket mass heater.
 
subject: JEditorPane HTML Anchor Links
 
Similar Threads
Question about hyperlink...
how to activate html-links in a JEditor pane
Help Info.
anchor tags within the jeditorpane
Hyperlinks in JEditorPane