This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setFocus in JButton is there any?

 
Jan Michael Soan
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello;
I have made a password protection program, but after typing the password and pressing the enter button notting happens.
I need to press the Tab button on my key board and press spacebar so that it will run.
My purpose is to press the JButton after typing & pressing the enter button on my keyboard, to do that i need to do setFocus, but i dont know it in Java can anyone pls. help me.
Thanks and GodBless.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am going to assume that you are using a JPasswordField or a JtextField for the password entry.
If so, you can just addActionListener to your Field and have it call the same method your JButton calls to perform the validation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic