Search code examples
javaswingwysiwygjtextpanehtmleditorkit

How to get current html element(tag) in JTextPane?


I am doing on WYSIWYG Html Editor using Java Program. I need When I click mouse on Paragraph element, It should be displays

tag in JOption dialog. Please advice me How can i do this?


Solution

  • See for example this one http://java-sl.com/JEditorPaneStructureTool.html

    In simple words you can get your HTMLDocument and get paragraph using getParagraphElement() method. Use viewToModel() method of JEditorPane to get caret offet for the clicked point.