java - How to listen to keypress events in a jdialog container? -


i have jdialog contains many rows of textfields , submit button. know if it's possible add eventlistener container trigger submit button.

one convenient way bind enter action via root pane's setdefaultbutton() method. can use action in key binding, shown here.

jdialog d = new jdialog(…); action submit = new abstractaction("submit") {      @override     public void actionperformed(actionevent e) {         // handle submit     } }; private jbutton b = new jbutton(submit); … d.getrootpane().setdefaultbutton(b); 

Comments