i think this is kind of what ur looking for , though its a jtextfield i think most of the essential stuff can transfer over
add(getJTextField0(), //the constrains and stuff); //the method to get the text field added public JTextField getJTextField0() { if (jTextField0 == null) { jTextField0 = new JTextField(); jTextField0.setText("Type Here"); jTextField0.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent event) { jTextField0KeyKeyReleased(event); } }); } return jTextField0; } // the key listener and text field input collector public void jTextField0KeyKeyReleased(KeyEvent event) { if (event.getKeyCode() == /* the enter key's code*/ ){ String input = jTextField0.getText(); // do what ever the command would do } }