I have a JTextArea component in my Swing code and I would like to add a handler/listener that is triggered anytime the user is typing (key events; key up, key down, etc.) text in the JTextArea.
According to the JavaDocs above, I can add a DocumentListener to it’s interna; Document model. However, when I implement DocumentListener, I have to write implementations for:
removeUpdateinsertUpdatechangedUpdate
These were not the type of methods I was expecting to see! I was expecting to see methods like onKeyDown(KeyEvent e), onKeyUp(KeyEvent e, etc.
So I ask: how can I get my JTextArea to respond to key up/down events? Thanks in advance!
Use
addKeyListener(it inherits from Component)