Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2010
    Posts
    5
    Rep Power
    0

    Default How can I restrict the length of string in JTextField?

    Hi all,

    How can I restrict the length of string in JTextField?

    I tried:

    private JTextField d2 = new JTextField(1);

    But, this is not working.

    Thanks.

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    6

    Default

    Use a JFormattedTextfield or a DocumentFilter.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Join Date
    Jun 2010
    Posts
    5
    Rep Power
    0

    Default

    Thanks. I will try.

  4. #4
    Join Date
    Jun 2010
    Posts
    5
    Rep Power
    0

    Default

    @ PhHein...

    I tried
    SwingUtils.setMaximumLength(d2, 1);

    and it is working for JTextField.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,588
    Rep Power
    23

    Default

    Where is the SwingUtils class defined? What package is it in? I can't find it in my API doc.

Similar Threads

  1. Validating for length of String
    By Bascotie in forum New To Java
    Replies: 1
    Last Post: 10-11-2009, 11:45 AM
  2. Replies: 1
    Last Post: 01-14-2009, 05:19 PM
  3. [SOLVED] String Length issue.
    By ChrisMayhew in forum New To Java
    Replies: 7
    Last Post: 01-11-2009, 03:16 AM
  4. Hejp with deleting string from JTextField
    By satin in forum New To Java
    Replies: 9
    Last Post: 11-08-2008, 11:05 PM
  5. Replies: 2
    Last Post: 03-25-2008, 05:49 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
  •