ThePrimedTNT
ThePrimedTNT

Reputation: 95

Undo And Redo In JTextPane Ignoring Style Changes

I was wondering if there is a way to ignore the text style changes in a JTextPane while using Swing's UndoManager?

Upvotes: 6

Views: 480

Answers (1)

camickr
camickr

Reputation: 324118

I've never tried it, but I would guess you can create a custom UndoManager.

You would need to override the undoableEditHappend(...) method to ignore an attribute change:

@Override
public void undoableEditHappened(UndoableEditEvent e)
{
    //  Check for an attribute change

    AbstractDocument.DefaultDocumentEvent event =
        (AbstractDocument.DefaultDocumentEvent)e.getEdit();

    if  (event.getType().equals(DocumentEvent.EventType.CHANGE))
        return
    else
        super.undoableEditHappened(e);
}

Upvotes: 5

Related Questions