Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 769
ThePrimedTNT Avatar asked Sep 26 '22 18:09

ThePrimedTNT


1 Answers

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);
}
like image 188
camickr Avatar answered Oct 11 '22 06:10

camickr