• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

keyboard action of my JButton

 
jhon max
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jhon max
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


sir i lost the focused again, when i declared an action for the JTextField...
 
Karthick Dharani Vidhya
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic