954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

JTextField

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!

red_evolve
Posting Whiz
313 posts since Jun 2003
Reputation Points: 53
Solved Threads: 1
 

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,
/Soo-Im

sooim3
Newbie Poster
11 posts since Jun 2003
Reputation Points: 10
Solved Threads: 0
 

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

red_evolve
Posting Whiz
313 posts since Jun 2003
Reputation Points: 53
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You