tags:

views:

33

answers:

2

I want to know whether we can find a tag in JEditorPane in java swing where my cursor is pointing.. For ex. following is the text content in my editor pane..

<html>
<head>
<body>
<div><!--Cursor inside the div tag--></div>
</body>
</html>

for instance suppose this is the text inside my editor pane. and my cursor is inside the tag. now what i want is a function that returns me the tag in which the cursor is. Is it possible?

Here cursor is in <div> tag so function should return "div" or "<div>".

+1  A: 

Yes. DIV is defined in HTML.Tag, so you can iterate though the elements of your HTMLDocument in a CaretListener. You can get the offsets from the attribute's child element.

trashgod
A: 

HTMLDocument doc=(HTMLDocument)pane.getDocument(); Element elem=doc.getCharacterElement(pane.getCaretPositon()); The take a look at the elem's attributes or elem.getParent() attributes because the char elem is text but the div is parent element's attribute.

StanislavL