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);
Trong trường hợp này tôi đã tìm thấy lỗi sau trong khi đặt văn bản trong vùng văn bản. Tôi không biết cách giải quyết.java.lang.IllegalStateException trong khi sử dụng Trình nghe Tài liệu trong TextArea, Java
Exception in thread "AWT-EventQueue-0"
java.lang.IllegalStateException: Attempt to mutate in notification
Tôi nghĩ rằng vấn đề là đặt văn bản trong tài liệu hoặc thiết lập tài liệu trong trình nghe tài liệu. Nhưng tôi không biết cách giải quyết vấn đề này. Làm ơn giúp tôi giải quyết vấn đề này.