• Post Reply Bookmark Topic Watch Topic
  • New Topic

on Contrl + Home how to set focuson to first field on the form?

 
reddy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a form.in that on control + home button focus should goto first field on the screen and control+end to last field on the screen.please give solution to this problem? urgent?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
reddy,

Please re-register with a user name that follows the guidelines of the Official JavaRanch User Name Conventions. As to your question, all you'd have to do is add a KeyListener to your JPanel, or whatever holds the fields, and in the keyPressed(KeyEvent) method check for control being pressed with event.isControlDown() and then test the KeyEvent's key code against the key code of the home or end keys ( event.getKeyCode()== KeyEvent.VK_HOME ), and then call requestFocus() on the appropriate field... You should end up with something like this in your KeyListener...



-Nate
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!