File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT / JFace and the fly likes enabling  push button with key listener Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "enabling  push button with key listener" Watch "enabling  push button with key listener" New topic
Author

enabling push button with key listener

red goliath
Greenhorn

Joined: Nov 23, 2001
Posts: 15
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

Joined: Oct 18, 2000
Posts: 4120

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


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Vinod Venugopal
Ranch Hand

Joined: Dec 06, 2000
Posts: 148
Add a keylistener to your textfield as below:
loginTxt.addKeyListener( new KeyAdapter()
{
public void keyReleased(KeyEvent ke)
{
//enable /disable your buttons..
}
});

- Vinod<br />-------<br />SCJP2
 
 
subject: enabling push button with key listener
 
Threads others viewed
disable OK button in JOptionPane when input is null
Pressing ENTER when Button is selected doesnt fire buttonActionPerformed...
JOptionPane.showConfirmDialog question
JFileChooser does not recognize the external OS behavior
button "Enter" key
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture