• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

InputVerifier, Document or DocumentFilter

 
Roel De Nijs
Sheriff
Posts: 10233
129
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I googled a bit around to find a solution for my problem "limit number of chars in a JTextField". So the code isn't the problem, but you have (at least) 3 different ways of doing this:
1) an InputVerifier
2) create a specific PlainDocument
3) create a specific DocumentFilter
4) maybe something i didn't find on google

Which is the best solution? Any guidelines in which one to use? Maybe one i must not use because it's really bad...

Kind regards,
Roel
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> "limit number of chars in a JTextField"

> 1) an InputVerifier

checks input to see if valid

> 2) create a specific PlainDocument

is the old way, see #3

> 3) create a specific DocumentFilter

this is the one you want

> 4) maybe something i didn't find on google

JFormattedTextField
 
Roel De Nijs
Sheriff
Posts: 10233
129
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,

Thanks for your quick reply. I will use the DocumentFilter then.

2 remarks though:
- in the Javadoc of JTextField a similar example is handled by creating a specific PlainDocument. so this should be altered
- if you want to set your FilterDocument, you have to do it like this (imho that's a bit messy):



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic