Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

IllegalStateException with JTextPane  RSS feed

 
Serghei Jelauc
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.
Does somebody can explain me why this exception is occured? I want when I will type the word "select", this word will change the colour.
When I run this small programm, ant type the word "select" this exception is occured.


Exception:
java.lang.IllegalStateException: Attempt to mutate in notification at javax.swing.text.AbstractDocument.writeLock(AbstractDocument.java:1070) at javax.swing.text.DefaultStyledDocument.setCharacterAttributes(DefaultStyledDocument.java:338) at TextPane.caretUpdate(TextPaneTest.java:45) at javax.swing.text.JTextComponent.fireCaretUpdate(JTextComponent.java:635) at javax.swing.text.JTextComponent$MutableCaretEvent.fire(JTextComponent.java:2822) at javax.swing.text.JTextComponent$MutableCaretEvent.stateChanged(JTextComponent.java:2844) at javax.swing.text.DefaultCaret.fireStateChanged(DefaultCaret.java:528) at javax.swing.text.DefaultCaret.changeCaretPosition(DefaultCaret.java:840) at javax.swing.text.DefaultCaret$UpdateHandler.insertUpdate(DefaultCaret.java:1120) at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:179) at javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:543) at javax.swing.JTextPane.replaceSelection(JTextPane.java:159) at javax.swing.text.DefaultEditorKit$DefaultKeyTypedAction.actionPerformed(DefaultEditorKit.java:801) at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1702) at javax.swing.JComponent.processKeyBinding(JComponent.java:2156) at javax.swing.JComponent.processKeyBindings(JComponent.java:2182) at javax.swing.JComponent.processKeyEvent(JComponent.java:2128) at javax.swing.JEditorPane.processKeyEvent(JEditorPane.java:1159) at javax.swing.text.JTextComponent.replaceInputMethodText(JTextComponent.java:3070) at javax.swing.text.JTextComponent.processInputMethodEvent(JTextComponent.java:2931) at java.awt.Component.processEvent(Component.java:3560) at java.awt.Container.processEvent(Container.java:1164) at java.awt.Component.dispatchEventImpl(Component.java:2595) at java.awt.Container.dispatchEventImpl(Container.java:1213) at java.awt.Component.dispatchEvent(Component.java:2499) at java.awt.EventQueue.dispatchEvent(EventQueue.java:319) at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
Please HELP me.
Thanks in advance.
Sorry for my English.
 
Bill Liteplo
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should note the writeLock in the method setCharacterAttributes in DefaultStyledDocument. Look at the javadoc API. Basically, that means that documents lock certain attributes/fields while they're being changed so that they can't be changed by two different threads at the same time.
Basically, I think you have to wait until the change event that was fired is completely done before you can change the character attributed of the document. Perhaps you can wrap your line that is causing the exception in a SwingUtilities.invokeLater call.


Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!