Do you want to do something like this ?
JTextField mTextField = new JTextField();
mTextField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_ENTER){
// something like...
//mTextField.getText();
// or...
//mButton.doClick();
}
}
});