• Post Reply Bookmark Topic Watch Topic
  • New Topic

enabling push button with key listener

 
red goliath
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a ok and cancel button on screen.After i fill the values for all the fields, on press of enter key i want the ok button to get activated and corresponding operation for login button to be performed.can any one give a sample code or tip
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add an ActionListener (or FocusListener) to your textfields that keeps track of which textfields have been filled out (or accessed). Then have the listener enable the OK button. As far as using the Enter key to launch the OK function, you'll just need to add a KeyListener that checks with the other listener (above) to see if all the fields are done, and then calls the same code your normal OK button ActionListener does.

-Nate

P.S. - Red Goliath... Please re-register with a username that follows the Official JavaRanch UserName Convention. ( UserNames in the form "first name" + space + "last name", and no obviously fake names... ) Thanks!
[This message has been edited by Nathan Pruett (edited December 19, 2001).]
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add a keylistener to your textfield as below:
loginTxt.addKeyListener( new KeyAdapter()
{
public void keyReleased(KeyEvent ke)
{
//enable /disable your buttons..
}
});
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!