Search code examples
javaimageswingtextjtextpane

How to read an image from text pane?


Say a plain text and an image are entered by a user into a text pane. How to separately read the text and the image from such text pane?


Solution

  • If you have HTMLEditorKit set as the default editor kit, then get all the elements of the document. Then iterate through those elements and look for image element. Then separate them from the text elements. Following links may come to your help:

    1. Element to string in HTMLDocument

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