DocumentListener and JTextField Confusion.
807591Apr 2 2008 — edited Apr 2 2008I'm working on an address book application. Yes, I know its lame, but it has been helping me become more familiar with swing.
Ive decided to have the name field in the address book capitalize the fist letter of each part of the persons name, and also force the other letters to be lowercase.
That was easy, but actually putting the corrected text back into the JTextField has been difficult for me. I'm using a DocumentListener and it works fine until I try to set the text, which causes the following to be generated:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Attempt to mutate in notification
at javax.swing.text.AbstractDocument.writeLock(AbstractDocument.java:1323)
at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:644)
at javax.swing.text.JTextComponent.setText(JTextComponent.java:1693)
at AddressBook_Core.correctNameField(AddressBook.java:846)
It seems to me that the JTextFields document is in use by the listener or something like that. I'm not really sure though. Anyway, I'm wondering if someone could tell me some more about why this problem occurred, and how to fix it.
Thanks in advance
Stuart R.