Hi, I'm using a JEditorPane to display HTML pages. I'm familiar with the HyperLinkUpdate listener to intercept mouse clicks on HTML links within a page, but I would like to intercept mouse clicks that land on HTML tags such as a table cell or an item in an ordered list. Can I do this with a JEditorPane ? If so, is it possible to determine which tag within the page has been clicked ? Can I then modify the HTML tag e.g. it's border colour ? Many thanks
The documentation for JEditorPane doesn't say much. Try installing a MouseListener (at the java.awt.Component level) and see if you get ANY events for clicks with System.out's. My guess is that they're intercepted by the JEditorPane and processed in a way that prevents you from dealing with them.
Take a look at HTMLEditorKit sources. In public void actionPerformed(ActionEvent e) method you can find the next code: Object href = getAttrValue(attr, HTML.Attribute.HREF); if (href != null) { if (currentOffset >= currentElement.getStartOffset() && currentOffset <= currentElement.getEndOffset()) { activateLink((String)href, doc, editor, currentOffset); return; } Code (markup): activateLink((String)href, doc, editor, currentOffset) fires HyperlinkEvent for all HyperlinkListener objects. I think that you can implement custom HTMLEditorKit and add support of necessary events for your project. Also it has sense to create custom class for JEditorPane.