相关疑难解决方法(0)

在TextArea,Java中使用Document Listener时出现java.lang.IllegalStateException

DocumentListener dl = new MessageDocumentListener();
((AbstractDocument) nboxArea.getDocument()).setDocumentFilter(new DocumentFilter() {
    public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
        string = string.replaceAll("\t", "");
        super.insertString(fb, offset, string,(javax.swing.text.AttributeSet) attr);
    }

    public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
        text = text.replaceAll("\t", "");
        //TODO must do something here
        super.replace(fb, offset, length, text,(javax.swing.text.AttributeSet) attrs);
    }
});

JTextArea evArea = (JTextArea) c;
evArea.getDocument().removeDocumentListener(dl);
evArea.setText(originalMessage);
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我在textarea中设置文本期间发现以下错误.我不知道该如何解决.

Exception in thread "AWT-EventQueue-0" 
java.lang.IllegalStateException: Attempt to mutate in notification …
Run Code Online (Sandbox Code Playgroud)

java swing listener

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

listener ×1

swing ×1