I have a text area with a document listener (below). When a user types into it, the input is saved into the string userInput, and the text is then removed from the text area so it is not displayed (using invokeLater). I need the Backspace key to do what it is supposed to do, remove the last character from the userInput string, but I don't know how to do that.
Please help,
Thanks
typedArea.getDocument().addDocumentListener(new DocumentListener() {
Document doc = (Document)typedArea.getDocument();
public void insertUpdate(DocumentEvent e) {
try {
userInput += typedArea.getText(doc.getLength()-1, 1);
System.out.println(userInput);
Runnable clearText = new Runnable() {
public void run() {
typedArea.setText("");
}
};
SwingUtilities.invokeLater(clearText);
}
catch(Exception ex) {
}
}
public void removeUpdate(DocumentEvent e) {
}
public void changedUpdate(DocumentEvent e) {
}
});
}