Corey Farwell
Corey Farwell

Reputation: 1916

Get the text content of individual Elements from an HTMLDocument

I have a jTextPane that has HTMLEditorKit set as the default editorKit. Calling getDocument on the jTextPane returns an HTMLDocument. I can traverse through this Document, navigating around the elements, but I can't seem to find a way to actually get the text contents of individual elements. I know in the DOM, there is a getTextContents() on each element, but I'm not working with the W3C DOM.

Upvotes: 4

Views: 1624

Answers (1)

trashgod
trashgod

Reputation: 205785

As you traverse the document's ElementIterator, shown here, use the getStartOffset() and getEndOffset() of each Element to calculate the parameters needed to call getText().

Upvotes: 3

Related Questions