I have Java Swing code that process user's input as follows:
public class UserEntryPane extends JPanel implements DocumentListener {
…
@Override
public void insertUpdate(DocumentEvent e) {
try {
String c = a.getText(...);
if (c.equals("\n")) {
System.out.println(...);
...
}
else {
...
}
} catch (Exception e) {
e.printStackTrace();
}
}
The issue is that this method is not invoked when Backspace is pressed. How can I detect user's Backspace to process it correctly?
Seems you use DocumentListener
.
Look at method removeUpdate
. It called, when you use backspace.
@Override
public void removeUpdate(DocumentEvent arg0) {
}