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!

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... ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.