views:

120

answers:

2

I'm displaying some tables as HTML code (rendered by a Freemarker template) with a JTextPane. I also have some HTML links in this HTML output which can be used to interact with the values of the table (For example "Delete a row" and stuff like this). Currently I always recreate the whole HTML output on each change and replace the whole document in the JTextPane with the new one. This is getting really slow and the JTextPane always changes the scroll position when I do this.

Is it possible to change only parts of the HTML code during runtime without replacing the whole document? In a real browser I would use the DOM and do something like document.getElementById("price").innerHTML = "$123.44". Is something like that possible with the HTMLDocument in a JTextPane?

+2  A: 

You can invoke getDocument() on the JTextPane to obtain an HTMLDocument, which can be traversed as suggested in this example. You can use replace(), setInnerHTML() or setOuterHTML() as required.

trashgod
A: 

Yes, it is. See javadoc :-), or could you clarify your question?

Istao