Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting maxlength in Swing  RSS feed

 
Jenny George
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi team,

How can we set maxlength of a JTextField? Could someone please give suggestions in this regard?

Thanks in advance,
Jenny
 
Michael Dunn
Ranch Hand
Posts: 4632
 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on validating data too.

I'm trying the class "InputVerifier". It looks promising and it seems as general as I would ever need.

http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/InputVerifier.html

Kaydell
 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, it seems that I need to use both a DocumentFilter and an InputVerifier.

I plan to have DocumentFilter to disallow characters that couldn't possibly be right, but allow partial entry that could be right if completed correctly.

I plan to have InputVerifiers to validate the input when the user is done such as when they try to go to another field in the JFrame.

Kaydell
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!