Results 1 to 8 of 8
  1. #1
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question [SOLVED] Key listener, unsure abt the tab key

    I have a key listener set up so that if the users tabs across to the field then the contents of the field can be cleared, however I want it to work that if the TAB key is pressed then as soon as the cursor goes to that cell then the textfield is cleared.

    I have it set so that if you navigate the form via mouse then it will clear the cell but cannot seem to get it right with the keylistener.

    for a start how do you express the tab key?

  2. #2
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    To be a little clearer, I am wanting a text field to clear on the cursor entering by the press of the tab key.

  3. #3
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    6

    Default

    To check if the tabkey is pressed:
    Java Code:
    public void keyPressed(keyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_TAB) {
    // code
    }
    That should work, I think.
    I die a little on the inside...
    Every time I get shot.

  4. #4
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question

    Thanks but that was similar to what I had and only lets me add 1 charector.

    can someone tell me what I should be looking for, I am trying to text field on entry from the tab key?

    thanks

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You might not want to use key listeners here. Instead either use key bindings or focus listeners.

  6. #6
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    so just to make sure i should be looking at focusGained?

  7. #7
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Thumbs up

    Thanks for the help, managed to get it working

    Java Code:
    private void txtJdateFocusGained(java.awt.event.FocusEvent evt) {
    
                        If ( isEnabled() == false);
                             txtJdate.setText("");

  8. #8
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    Continuing on from this, there is a help button on my application, you can obviously access help by click however I am looking at accessing it by pressing f1.

    This will be a keyEvent however can u just confirm that this has to be in public class or should i be able to use in private?

    Thanks in advance

Similar Threads

  1. #key listener problem
    By mij1_7 in forum New To Java
    Replies: 2
    Last Post: 02-14-2009, 09:02 PM
  2. Listener for print job
    By pjmorce in forum Advanced Java
    Replies: 1
    Last Post: 11-14-2008, 08:02 AM
  3. Regarding Listener
    By adeeb in forum AWT / Swing
    Replies: 2
    Last Post: 06-20-2008, 11:07 PM
  4. Regarding Listener
    By adeeb in forum AWT / Swing
    Replies: 2
    Last Post: 06-10-2008, 02:00 AM
  5. Listener for SWT event
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-08-2008, 09:04 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
  •