Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default 2 Restriction on TextField

    Hello,

    Can someone please help me with a question,
    I need to have a textField where the user enters a 4 digit number, it should also be a TextField.PASSWORD, how can i add a TextField.NUMERIC restriction?

    thank you

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

    Default

    Have you tried using a JFormattedTextField? Or if it must be a JPasswordField you could always add a TextFilter to the field's Document.

  3. #3
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    JFormatedTextField in j2me? clcd ?
    Are you sure?
    i tried to find someting.. but the only i found to do this is by implementing the ItemStateListener somehow.
    I searched the api's but it wasn't realy clear if i could just "add a restruction" it it's constructor.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default

    JFormatedTextField in j2me? clcd ?
    No, I'm sure Fubarable responded without noticing that this was in a Java ME section of the forum.

    It's a long time since I did any Java ME, but I think you can achieve your requirement by using TextField.NUMERIC | TextField.PASSWORD (or possibly TextField.NUMERIC + TextField.PASSWORD which, according to the documentation, should give the same result)

    Unless they've fixed it (not likely, it was around for 3-4 years already when I stumbled across it) there's a bug in the implementation of setConstraints(...), so the only safe way to set the constraints is in the TextField's constructor.

    db

  5. #5
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default Thank you

    Now it works :), good with both "+" and "|" thank you verry much.

Similar Threads

  1. JFileChooser restriction
    By sehudson in forum New To Java
    Replies: 2
    Last Post: 03-14-2011, 03:21 AM
  2. 4 digit restriction
    By GTM in forum Java Applets
    Replies: 3
    Last Post: 12-28-2010, 02:26 AM
  3. Access Restriction error
    By kraut in forum Eclipse
    Replies: 0
    Last Post: 06-19-2010, 01:07 AM
  4. Replies: 7
    Last Post: 02-19-2010, 11:03 AM
  5. Error: Access restriction
    By livnihai in forum Eclipse
    Replies: 1
    Last Post: 11-25-2009, 06:53 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
  •