Making a JDialog button respond to the Enter key

Question!

I have a JQueryDialog with a text field, an OK button and a cancel button.

I want to be able to hit the enter key after filling in the text fields and have it do the same action as when I click the OK button.



Answers

The code is almost correct. I would change the if comparison and use the correct method as noted below.

if (KeyEvent.VK_ENTER == event.getKeyCode()) {
                yourButton.doClick();
            }


You may be interested in this minor mode I created at http://github.com/vohrta/regtab.

It makes it so that when you press the tab key either a tab character (if indent-tabs-mod is not nil) or tab-width spaces will be placed at point. The mode is also capable of handling what you may consider regular behavior on a region of selected text and shift-tabbing to remove tabs at the beginning of the line (or set of lines).

You can enable or disable it at any time by pressing M-x regtab-mode.

By : Jake


I think trey jackson's answer is probably what you want, except possibly use 'self-insert-command instead of 'indent-for-tab-command. I personally prefer emacs' default behavior, but self-insert-command does what it says instead of trying to do anything fancy like make sure your code is well-formatted.

The few times I actually want to insert a tab (not indent) I press M-i.



This video can help you solving your question :)
By: admin