posted 15 years ago
You might be able to do this by setting an overall key listener for your panel. Normally this would be a bad idea as it would slow down your application, but if this is just a temporary dialog box you might be able to get away with it.
Note that this is just a (poor) proof of concept. I would not want to see any real code go out like this. In particular, I am cheating by setting the key listener to the JPanel, then resetting the focus to the JPanel whenever anything happens. This results in the very poor experience that the user will never see focus where they want it. You would probably be much better off having a common key listener that gets assigned to each field (and button), so no matter where the focus is, the Enter key will still work in a desirable manner.
Regards, Andrew