Hi..I've been searching all around to find out whether I could submit an entry in a JTextField by clicking a separate button created (say, a "submit" button).
It seems that, the value entered in the text field will only be appended if I press the Enter key. Can someone please help? Thx!

14 Years
Discussion Span
Last Post by red_evolve

A combination of events can be used for the same listener; listening to i.e. when a certain key is pressed by adding a KeyAdapter's KeyEvent, and listening to when a certain button is being pressed by using the ActionListener's ActionEvent.

So if i.e. a "ok" button should do something one could write a listener class that do the following:

Class OkListener extends KeyAdapter implements ActionListener {

   public void keyTyped(KeyEvent ke) {
      // Code for what happens to the JTextField when a certain key is be pressed...

   public void actionPerformed(ActionEvent ae) {
      // Code for what happens to the JTextField when a button is clicked on...


Hope this is of some help,


Hehe... I've got it already...because my assignment duedate was yesterday. It's actually a very simple way of solving...But thank you anyway... ;)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.