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 and the fly likes button action command from keylistener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "button action command from keylistener" Watch "button action command from keylistener" New topic
Author

button action command from keylistener

Stephen Boston
Ranch Hand

Joined: Jul 14, 2005
Posts: 165
I'm stumped. I have a nice button action event to run a login process for my app. My GUI has 2 fields (user id and password) and two buttons (Login and Cancel)

My login button (bnLogin) has an actionhandler assigend to it to process its events. I want to add a keylistener to my password textfield so when the enter key is pressed it will accept the text and call the bnLogin action.

Here is a section of my code.


My searches on this has turned up nothing.

Can I do what I'm wanting to do here or should I rethink the way I run the login process?

Thanks for any help!

Steve


Steve<br /> <br />No matter where you go, there you are.<br /> <br />"My evil self is at the door, and I have no power to stop it."
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

You can give textfield Actions as well. You don't need to use a KeyListener. Do it the same way you do a button.


GenRocket - Experts at Building Test Data
Stephen Boston
Ranch Hand

Joined: Jul 14, 2005
Posts: 165
Ding! Lightbulb just went on.

Thanks!
Stephen Boston
Ranch Hand

Joined: Jul 14, 2005
Posts: 165
This works much better!


Thanks for pointing me in the right direction!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: button action command from keylistener
 
Similar Threads
Swing New User Interface - Opinions Please
organising panels
Remove Keystroke event for enter key
Key Event listener question.
run-time error HELP!