• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

set the max length of a JTextField

 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I restrict the maximum length of the value in a Password Field as well as JTextField. I'm using a JPasswordField to get the password form the user & I want to restrict the length of the password to 8 characters. Plz. help me do this,as well as in a JTextField.
Netharam.
Happy middling with java.
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
You are going to have to use this

public JPasswordField(Document doc,
String txt,
int columns)

Constructor.
The Document that you pass in will have to be a sub-class that overrides insertString(int offset, String str, AttributeSet a). In the insertString method check to see if the length is 8 or more, if it is then don't do anything.
[ July 23, 2002: Message edited by: Ibrahim Hashimi ]
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have a look at JFormattedField.
 
reply
    Bookmark Topic Watch Topic
  • New Topic