wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes keyboard action of my JButton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "keyboard action of my JButton" Watch "keyboard action of my JButton" New topic
Author

keyboard action of my JButton

jhon max
Ranch Hand

Joined: Jan 06, 2010
Posts: 45
hi, I need some help about this user entry phase of my program (password prompting)



I'm having some problem regarding with the keyboard press with my jbutton inside the frame.
I dont have any problems with the keyboard event.. but the problem is in the "focus"(i dont know if that is the best word to express the problem),

anyway the problem is, when i press the button the "focus" is starting on the text field(well ofcourse it will start on the first component), so when i press the "Enter" key, the button doesnt fire any keyboard event
i have to go through the two textfields first before i can fire the keyboard event of my button.

What I want is, even the "focus" is in either of the textfields, when i press the button it will automatically fires the keyboard event that i want...

I hope you understand my concern, sorry for bad expression of my problem(bad english)
Please I desperately need some help about this. Thanks in advance!
Karthick Dharani Vidhya
Ranch Hand

Joined: Feb 23, 2008
Posts: 88
in line number 63 and 67, when registering the key board action, use JComponent.WHEN_IN_FOCUSED_WINDOW. Please see the code below.



Not sure if this is what you needed. Please do this change and see if this gives you the expected behaviour.


Karthick D V
jhon max
Ranch Hand

Joined: Jan 06, 2010
Posts: 45
oh sir.. how can I thank you for that one .. thats a VERY BIG help ..! thank you so much!!! thank you thank you! ... that solved my problem !! thank you!
jhon max
Ranch Hand

Joined: Jan 06, 2010
Posts: 45


sir i lost the focused again, when i declared an action for the JTextField...
Karthick Dharani Vidhya
Ranch Hand

Joined: Feb 23, 2008
Posts: 88
Hi,

First question is why do you want to add a action listener to a Text field? What is the functionality that you are trying to acheive by doing so.

One solution for your above issue will be to add a Key Listener to your password field and check if the pressed key is ENTER or not. If ENTER, then delegate the action to USERCONFIRMATIONBTN or call USERCONFIRMATIONBTN.doClick() as shown below

jhon max
Ranch Hand

Joined: Jan 06, 2010
Posts: 45
thank you sir.. I resolved it in this way


inside of the button action I added the passwordField then retrieved its generated password,
sorry for asking too much, i didnt have any idea that i can still call a different component from another action event..
 
wood burning stoves
 
subject: keyboard action of my JButton