I just started using java and am not very good, so if you could help me that would be awesome! I'm making a Swing
application and want to close it only when a certain key is pressed. Is there a way to do this?
Going against the other X answers here, I'm going to recommend that you not use a KeyListener but rather use key bindings. This is a higher level abstraction, and helps you avoid focus issues that come with use of KeyListeners. You can find out more about key bindings in the Swing tutorials here: How to use Key Bindings
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With