TextEditorPane dirty flag not resetting to clean

Questions on using RSyntaxTextArea should go here.

Moderator: robert

TextEditorPane dirty flag not resetting to clean

Postby sugref2 » Wed Dec 18, 2013 2:37 pm

The dirty flag on TextEditorPane is not being reset to false when all edits are undone.
(I am assuming that all edits are Undoable and that any non-Undoable edit is handled specially by the particular application)

There are a number of approaches to a fix

[list=]allowing RUndoManager to be subclassed in RTextArea
exposing UndoManager in RTextArea as in UndoManager getUndoManager()
providing canUndo(), canUndo() in RTextArea[/list]

The following snippets might help; it is from a subclass of TextEditorPane that gets over the problem

java code:

public void undoLastAction() {
final UndoManager undoManager = getUndoManagerHACK();
if (undoManager != null)
if (undoManager.canUndo())

UndoManager getUndoManagerHACK() {
final AbstractDocument doc = (AbstractDocument) getDocument();
final UndoableEditListener[] undoMgrArray = doc
if (undoMgrArray == null || undoMgrArray.length == 0)
return null;
return (UndoManager) undoMgrArray[0];

void setDirtyHACK(boolean dirty) {
try {
final Class<?> claz = Class.forName(TextEditorPane.class.getName());
final java.lang.reflect.Method m = claz.getDeclaredMethod("setDirty",
m.invoke(this, dirty);
catch (final Throwable e) {

Re: TextEditorPane dirty flag not resetting to clean

Postby robert » Sun Dec 29, 2013 4:02 pm

Thanks sugref2! I'll take a look.
User avatar
Posts: 850
Joined: Sat May 10, 2008 5:16 pm

Return to Help

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest