Results 1 to 3 of 3
  1. #1
    birdofprey is offline Member
    Join Date
    Feb 2008
    Posts
    3
    Rep Power
    0

    Default how to focus to another JTextfield?

    If i create an object where the object is return within a private function and added into jContentPane, something like this

    jContentPane.add(getTextField1);
    jContentPane.add(getTextField2)


    Is there it anyway for me to have my cursor focus onto the next JTextfield once the user enter his info for that field?

    Once he's done with "getTextField1" hits enter and it will jump to the next field "getTextField2"?

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java provides for navigation out of a JTextField to the next focusable component in the containment hierarchy by holding down the shift key and pressing the tab key. Pressing the enter key while the cursor is in a JTextField fires an ActionEvent. To override this behavior may be complicated.

  3. #3
    newmember is offline Member
    Join Date
    Dec 2007
    Posts
    8
    Rep Power
    0

    Default

    you can use "getTextField2.grabfocus() " method within keylistener of getTextField1 when key "Enter" is pressed.

Similar Threads

  1. set focus to the textfield
    By paty in forum New To Java
    Replies: 2
    Last Post: 07-09-2010, 09:28 AM
  2. add JToolTip on focus gained forJTextField
    By ismailsaleh in forum AWT / Swing
    Replies: 6
    Last Post: 02-01-2008, 01:02 PM
  3. JTable Focus Traversal
    By helios_lie in forum AWT / Swing
    Replies: 1
    Last Post: 12-20-2007, 11:27 AM
  4. help with JTextfield
    By gary in forum New To Java
    Replies: 4
    Last Post: 07-11-2007, 02:58 PM
  5. Focus
    By Marty in forum AWT / Swing
    Replies: 1
    Last Post: 05-31-2007, 03:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •