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);
In questo caso ho trovato il seguente errore durante testo impostato in textarea. Non so come risolvere.java.lang.IllegalStateException durante l'utilizzo di Document Listener in TextArea, Java
Exception in thread "AWT-EventQueue-0"
java.lang.IllegalStateException: Attempt to mutate in notification
Penso che il problema sia impostare il testo nel documento o impostare il documento nel listener del documento. Ma non so come risolvere questo. Per favore aiutami a risolvere questo problema.