How can I determine which character was deleted from a JTextArea by the 'Delete' or 'Backspace' keys?
Created May 4, 2012
Sandip Chitale JTextArea is a 'view' on javax.swing.text.PlainDocument. The PlainDocument class supports registration of javax.swing.event.DocumentListener. Thus you could register a DocumentListener and in the
public void removeUpdate(DocumentEvent e)call back figure out what is being deleted.
ALternatively you could install an alternate keymap whereby you intercept the 'Delete' and 'Backspace' key.
Please look at -
- http://java.sun.com/products/jdk/1.2/docs/api/javax/swing/text/JTextComponent.html
- http://java.sun.com/products/jdk/1.2/docs/api/javax/swing/text/JTextComponent.html#setKeymap(javax.swing.text.Keymap)
- http://java.sun.com/products/jdk/1.2/docs/api/javax/swing/text/Keymap.html
- http://java.sun.com/products/jdk/1.2/docs/api/javax/swing/text/DefaultEditorKit.html#deletePrevCharAction
- http://java.sun.com/products/jdk/1.2/docs/api/javax/swing/text/DefaultEditorKit.html#deleteNextCharAction