Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

set the max length of a JTextField  RSS feed

 
netharam ram
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • 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.
 
Sayed Ibrahim Hashimi
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • 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 ]
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have a look at JFormattedField.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!