Showing posts with label edited. Show all posts
Showing posts with label edited. Show all posts

Friday, 11 January 2008

Checking if a JEditorPane has been edited (changed)

While I was looking for a way to check if a JEditorPane's text had been changed since the last save, I found a site that actually wanted me to pay for the answer. Bloody cheek. It isn't that tough, but it took a bit of reading. All that is needed is to install a DocumentListener into the editor pane's document. You can download a complete example swing-editor-src-0.1.jar which includes an ant build file. Just type "ant run" at the shell prompt to run it. You will need ant and JDK >= 1.5 (it may work in older JDKs, but I used 1.5 so I can't be sure).

The document can't tell when your program has saved the document (ie, it is no longer "dirty"), so you need to call setDirty(false) after a save.