DocumentListener dl = new MessageDocumentListener();
((AbstractDocument) nboxArea.getDocument()).setDocumentFilter(new DocumentFilter() {
public void insertStrin
You cannot modify the document inside the DocumentListener. Write a custom Document instead, which overrides the insertString() or remove() methods.
From Java Tutorials: How to write a DocumentListener
Document listeners should not modify the contents of the document; The change is already complete by the time the listener is notified of the change. Instead, write a custom document that overrides the insertString or remove methods, or both. See Listening for Changes on a Document for details.