Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Fubarable

Thread: chosing among the 3 key events

  1. #1
    sandeshyadav is offline Member
    Join Date
    Feb 2012
    Posts
    13
    Rep Power
    0

    Default chosing among the 3 key events

    i have a JTextField txtname in which the user should be warned if he types numeric characters 0-9 or other special symbols .... so what i want to ask is whether the function to prevent this should be written in keyListener's KeyPressed Method or KeyReleased Method or KeyTyped Method ?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: chosing among the 3 key events

    My suggestion is "none of the above". If you want to check input before it has been posted to the JTextField, use a DocumentFilter. To do this, get the JTextField's document, cast it into a PlainDocument and call setDocumentFilter(...) on this. If you need examples, search this forum and you'll see several (many written by me in fact).
    DarrylBurke likes this.

  3. #3
    sandeshyadav is offline Member
    Join Date
    Feb 2012
    Posts
    13
    Rep Power
    0

    Default Re: chosing among the 3 key events

    Thanx i learned DocumentFilter ....... and going to apply it on my project ....... i hope it will work :) :)
    Thanx again ...........

  4. #4
    sandeshyadav is offline Member
    Join Date
    Feb 2012
    Posts
    13
    Rep Power
    0

    Default Re: chosing among the 3 key events

    WOW it worked ....... and so wonderfully ..... this is one of the coolest thing that i learned in java.......... thanx again.........

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

Similar Threads

  1. Key Events
    By rdjava in forum Java Gaming
    Replies: 0
    Last Post: 04-15-2011, 09:02 AM
  2. typed events vs untyped events.
    By Drun in forum SWT / JFace
    Replies: 0
    Last Post: 11-23-2009, 01:22 PM
  3. Mouse events, are they best or only way to go?
    By dbashby in forum New To Java
    Replies: 2
    Last Post: 04-10-2009, 05:34 PM
  4. Need Help with events
    By Gatts79 in forum AWT / Swing
    Replies: 3
    Last Post: 09-23-2008, 04:18 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
  •