• Post Reply Bookmark Topic Watch Topic
  • New Topic

text filed and button validation  RSS feed

 
ramesh kancherla
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This is ramesh kancherla. I am creating a swing frame.in my swing frame buttons and text fields are there.

one button name addEmail is link to one text field.
when entering text into text field addEmail button will enable.
when removing text from textfield by backspace or delete key or any other way
after removed text from textfield if it is empty then addEmail button will go to disable mode.

i am checking with text field empty or not when key is pressed.
But disable mode and enable mode is not properly working.

can any one please give me an idea how do I implement it.

Thanks & Regards
Ramesh k
 
Campbell Ritchie
Marshal
Posts: 56227
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try adding Listeners to your text fields, but that doesn't sound at all like good programming to me. Nor does enabling and disabling buttons depending on whether text is being added or deleted sound good to me.

If you have an empty text field, or text which doesn't match an e-mail address (do a search through JavaRanch for regular expressions for e-mail addresses, which can be very long), you have various options from your button:
  • Throw Exception.
  • Pop up JOptionPane.
  • Delete text.
  •  
    G Estes
    Ranch Hand
    Posts: 62
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You have action listeners (button events, etc...) as well as key listeners (where you can take certain actions on various key strokes) as well as others.

    Give us more of you requirements and someone can assist perhaps?
     
    Michael Dunn
    Ranch Hand
    Posts: 4632
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
     
    ramesh kancherla
    Ranch Hand
    Posts: 124
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for your help.it is working fine
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!