Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Undo Redo problem for JTextPane

843804Jun 17 2005 — edited Mar 21 2007
I'm trying to build a Editor based on JTextPane that has syntax highlighting, indentation, etc. It's like an IDE without actually doing compilation or debugging. I'm working on undo/redo when I run into this problem. Basically, my document extends DefaultStyledDocument and override the insertString method. Now, whenever user inserts a segment of text, i update my parser and ask my parser what color I should set the segment of text to. When i get the appropriate color, I call setCharacterAttribute() to set the color. For undo/redo, this has generated two UndoEvents. One as an INSERT documentEvent and the other as a CHANGE documentEvent for the color change. Therefore, for my UndoableEditListener, it receives two events. Now, when the user press undo, originally it was undoing the color change, then the insert change. This is not what I want. I want it as a single undo action. Any suggestions on how I should go about this?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 18 2007
Added on Jun 17 2005
5 comments
568 views