java.lang.IllegalStateException while using Document Listener in TextArea, Java

后端 未结 2 635
傲寒
傲寒 2020-12-06 11:30
DocumentListener dl = new MessageDocumentListener();
((AbstractDocument) nboxArea.getDocument()).setDocumentFilter(new DocumentFilter() {
    public void insertStrin         


        
2条回答
  •  执念已碎
    2020-12-06 12:17

    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.

提交回复
热议问题