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", "");
super.replace(fb, offset, length, text,(javax.swing.text.AttributeSet) attrs);
}
});
JTextArea evArea = (JTextArea) c;
evArea.getDocument().removeDocumentListener(dl);
evArea.setText(originalMessage);
在本例中,我在文本区域中设置文本时发现以下错误。我不知道怎么解决。
Exception in thread "AWT-EventQueue-0"
java.lang.IllegalStateException: Attempt to mutate in notification
我认为问题是在文档中设置文本或在文档侦听器中设置文档。但我不知道怎么解决这个问题。请帮我解决这个问题。