How would I go about doing this?
I have a jTextField and a jButton. Normally what happens is user enters something in the jTextField and clicks the button and:
Code:
private void jButtonEnterActionPerformed(java.awt.event.ActionEvent evt) {
}
is executed, as you would expect.
However what I want is, for the user to be able to simple press enter after putting something in the jTextField and
Code:
private void jButtonEnterActionPerformed(java.awt.event.ActionEvent evt) {
}
will execute.
I am using Netbeans.
Previously I tried this:
I added
Code:
private void jTextFieldInputKeyPressed(java.awt.event.KeyEvent evt) {
if(evt.getKeyCode() == 10) {
// same as code jButtonEnterActionPerformed executed here.
}
}
However I would prefer not to do this is just repeating the same line of codes as another function, and I am sure there is a simpler method. So could someone point me to the right direction?