请问一下DocumentListener的问题??

bbkills 2004-05-04 06:34:03
我对一个JTextPane的getDocument()注册了一个DocumentListener,然后在覆盖了那三个changedUpdate,insertUpdate,removeUpdate函数.,三个都是直接调用一个使JTextPane(通过StyleDocument.setCharacterAttributes())某一处变色的函数,但运行时去出现:
java.lang.IllegalStateException: Attempt to mutate in notification
at javax.swing.text.AbstractDocument.writeLock(Unknown Source)
at javax.swing.text.DefaultStyledDocument.setCharacterAttributes(Unknown Source)
at HighLight.highlight(HighLight.java:38)
at HighLight.update(HighLight.java:18)
at NewTab$TextDocumentAction.removeUpdate(NewTab.java:62)
at javax.swing.text.AbstractDocument.fireRemoveUpdate(Unknown Source)
at javax.swing.text.AbstractDocument.handleRemove(Unknown Source)
at javax.swing.text.AbstractDocument.remove(Unknown Source)
at javax.swing.text.DefaultEditorKit$DeletePrevCharAction.actionPerformed(Unknown Source)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
然后去掉DocumentListener,用一个按钮去调用那个函数,运行却能够得到正确的效果.请问是不是DocumentListener时不能改变StyleDocument的内容.怎么解决.谢谢!!
...全文
52 2 点赞 打赏 收藏 举报
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
turbochen 2004-05-06
Document模型不是线程安全是。你一定是在调用setCharacterAttributes时又在做其它的INSERT或UPDATE的操作。
  • 打赏
  • 举报
回复
panpan221 2004-05-06
新手学习,帮你顶
  • 打赏
  • 举报
回复
相关推荐
发帖
Java SE
加入

6.2w+

社区成员

Java 2 Standard Edition
申请成为版主
帖子事件
创建了帖子
2004-05-04 06:34
社区公告
暂无公告