Hej.
Jeg har et rigtig irriterende problem.
Jeg har erfarret at det ikke er muligt at sætte teksten af et TextField caretUpdate hos en CaretListener.
Får hvert fald følgende meddelse hvis jeg prøver med setText():
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Attempt to mutate in notification
at javax.swing.text.AbstractDocument.writeLock(AbstractDocument.java:1340)
at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:661)
at javax.swing.text.JTextComponent.setText(JTextComponent.java:1707)
at GenerateDialog.GenerateDialogPanel.caretUpdate(GenerateDialogPanel.java:91)
at javax.swing.text.JTextComponent.fireCaretUpdate(JTextComponent.java:405)
at javax.swing.text.JTextComponent$MutableCaretEvent.fire(JTextComponent.java:4401)
at javax.swing.text.JTextComponent$MutableCaretEvent.stateChanged(JTextComponent.java:4423)
at javax.swing.text.DefaultCaret.fireStateChanged(DefaultCaret.java:799)
at javax.swing.text.DefaultCaret.changeCaretPosition(DefaultCaret.java:1274)
at javax.swing.text.DefaultCaret.handleSetDot(DefaultCaret.java:1170)
at javax.swing.text.DefaultCaret.setDot(DefaultCaret.java:1151)
at javax.swing.text.DefaultCaret$Handler.insertUpdate(DefaultCaret.java:1719)
at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:202)
at javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:751)
at javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:710)
at javax.swing.text.PlainDocument.insertString(PlainDocument.java:131)
at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:672)
at javax.swing.text.JTextComponent.setText(JTextComponent.java:1707)
at GenerateDialog.GenerateDialogPanel.caretUpdate(GenerateDialogPanel.java:91)
at javax.swing.text.JTextComponent.fireCaretUpdate(JTextComponent.java:405)
at javax.swing.text.JTextComponent$MutableCaretEvent.fire(JTextComponent.java:4401)
at javax.swing.text.JTextComponent$MutableCaretEvent.stateChanged(JTextComponent.java:4423)
at javax.swing.text.DefaultCaret.fireStateChanged(DefaultCaret.java:799)
at javax.swing.text.DefaultCaret.changeCaretPosition(DefaultCaret.java:1274)
at javax.swing.text.DefaultCaret.handleSetDot(DefaultCaret.java:1170)
at javax.swing.text.DefaultCaret.setDot(DefaultCaret.java:1151)
at javax.swing.text.DefaultCaret$Handler.insertUpdate(DefaultCaret.java:1719)
at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:202)
at javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:751)
at javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:710)
at javax.swing.text.PlainDocument.insertString(PlainDocument.java:131)
at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:672)
at javax.swing.text.JTextComponent.replaceSelection(JTextComponent.java:1365)
at javax.swing.text.DefaultEditorKit$DefaultKeyTypedAction.actionPerformed(DefaultEditorKit.java:876)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1658)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2851)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2886)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2814)
at java.awt.Component.processEvent(Component.java:5885)
at java.awt.Container.processEvent(Container.java:2105)
at java.awt.Component.dispatchEventImpl(Component.java:4469)
at java.awt.Container.dispatchEventImpl(Container.java:2163)
at java.awt.Component.dispatchEvent(Component.java:4295)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1881)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:749)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1025)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:892)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:713)
at java.awt.Component.dispatchEventImpl(Component.java:4339)
at java.awt.Container.dispatchEventImpl(Container.java:2163)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4295)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:604)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
Hvad kan man gøre for at kunne sætte teksten?