Results 1 to 4 of 4
  1. #1
    Anne is offline Member
    Join Date
    Aug 2015
    Posts
    18
    Rep Power
    0

    Default How to use try catch for no. of characters in a text field & for blank fields?

    All the following questions are about Netbeans' Graphical User Interface. I want to know about some common uses of try catch:

    • a) if you have a text field in Netbeans' GUI, to make sure the user types at least a certain number of characters in it
    • b) to check for nothing typed in a field, or for fields containing white space only
    • to make sure a user doesn't type letters in a field intended for number
    • to make sure a user doesn't type a double in a field for integers and vice versa


    Thank you for your help! Any other information about uses of try catch or something else that's related will be appreciated.

    In case try catch cannot be used for one or more of those purposes, can you explain what I can use to achieve that purpose?
    Last edited by Anne; 08-13-2015 at 08:53 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: How to use try catch for no. of characters in a text field & for blank fields?

    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Aug 2015
    Location
    Northern California
    Posts
    31
    Rep Power
    0

    Default Re: How to use try catch for no. of characters in a text field & for blank fields?

    try catch blocks are for catching exceptions but your questions seem like you want to validate a Text Field input.
    The catch Blocks (The Java™ Tutorials > Essential Classes > Exceptions)

    JTextField needs a document listener which will listen for changes to the JTextField. If you change the contents of the JTextField it will fire a block of code that you create specifically to handle your logic.
    (See Creating a Validated Text Field)
    How to Use Text Fields

  4. #4
    Anne is offline Member
    Join Date
    Aug 2015
    Posts
    18
    Rep Power
    0

    Default Re: How to use try catch for no. of characters in a text field & for blank fields?

    Thanks for the replies! The websites were very helpful!

Similar Threads

  1. Adding Text from button to text field.
    By Irish Rayray in forum AWT / Swing
    Replies: 3
    Last Post: 02-13-2013, 06:38 PM
  2. Replies: 7
    Last Post: 03-05-2011, 09:25 AM
  3. Replies: 4
    Last Post: 10-10-2010, 10:57 AM
  4. Remove a Blank Line from Text file
    By nitinverma in forum CLDC and MIDP
    Replies: 8
    Last Post: 06-15-2010, 06:12 AM
  5. Special characters in text fields
    By Felissa in forum Web Frameworks
    Replies: 0
    Last Post: 06-27-2007, 04:47 PM

Posting Permissions

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