I have a JTextArea and I'd like to listen when the user pastes text in the JtextArea. Specifically, I'd like to do the following:
Get the text they pasted, remove whitespaces, and replace the JTextArea text with the edited text without spaces (rather than the original text the user pasted).
How can I do this using a DocumentListener, and avoiding java.lang.UnsupportedOperationException: Not supported yet.
, which comes as a result of the following code:
public void insertUpdate(DocumentEvent de) {
final String replace = jTextArea1.getText().replaceAll("\\s","");
SwingUtilities.invokeLater(new Runnable() {
public void run() {
jTextArea1.setText(replace);
}
});
}