Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a method after the space bar is pressed in a JTextArea

Sorry for what is likely a simple question, but how can I call a method every time the space bar is pressed in a JTextArea? I have tried attaching a keylistener to the text area, but I wasn't able to get that to work. Thanks.

like image 880
nuclearPigi Avatar asked Dec 26 '22 06:12

nuclearPigi


1 Answers

Read the Swing tutorial on How to Use Key Bindings.

The tutorial has examples and you can find plenty of other examples in the forum.

When you create the custom Action that you want to execute you would extend TextAction.

like image 159
camickr Avatar answered Feb 26 '23 14:02

camickr