Results 1 to 3 of 3
- 09-20-2011, 07:49 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 9
- Rep Power
- 0
Can HyperlinkListener detect the click on the anchor in JEditorPane?
Hi:
I have a html document and I want to put it inside a JEditorPane to review. I only need to read so the JEditorPane has 'setEditable(false)'. There are many anchors (<a>) inside this html document which points to somewhere within the same html document. I would like 'the click on the anchor wil make JEditorPane to scroll to the place where the anchor points to.
Can I write a HyperlinkListener for this JEditorPane to make this work? Anybody share the source code?
Appreciate
Lily
- 09-20-2011, 08:05 AM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Re: Can HyperlinkListener detect the click on the anchor in JEditorPane?
Not sure, but I think this code might work. I think the frame hyperlink event is for internal link as oppose to loading a completely new page in the else condition.
Java Code:public HyperlinkListener createHyperLinkListener() { return new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (e instanceof HTMLFrameHyperlinkEvent) { ((HTMLDocument)html.getDocument()).processHTMLFrameHyperlinkEvent( (HTMLFrameHyperlinkEvent)e); } else { try { html.setPage(e.getURL()); } catch (IOException ioe) { System.out.println("IOE: " + ioe); } } } } }; }
- 09-20-2011, 08:33 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 9
- Rep Power
- 0
Re: Can HyperlinkListener detect the click on the anchor in JEditorPane?
that is not working. I think the right code is
String ref = evt.getURL().getRef();
if (ref != null && ref.length() > 0)
{
System.out.println("reference to scroll to = " + ref);
scrollToReference(ref);
}
However, the 'evt.getURL' returns null. I am not sure what I am missing. Anybody knows? Please help.
Thanks,
lily
Similar Threads
-
How can i detect the word in a text editor, when i right click on it ??
By Swoyam in forum AWT / SwingReplies: 1Last Post: 06-27-2011, 06:11 PM -
gridBagLayout anchor ... wanna move all components to top left
By alinaqvi90 in forum AWT / SwingReplies: 16Last Post: 11-17-2010, 01:02 PM -
anchor tag in html
By meghana in forum EclipseReplies: 3Last Post: 08-18-2010, 03:21 PM -
How to detect double click with a JFrame
By Jary316 in forum New To JavaReplies: 3Last Post: 01-05-2009, 08:39 PM -
Demonstrating the HyperlinkListener
By Java Tip in forum javax.swingReplies: 0Last Post: 04-23-2008, 08:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks