• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Fixing Max. char in JTextField

 
Manoj Tyagi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all,
I am working on JTextField & want that my JTextField should not take more than 1(or any fixed no.) chatacter. How to make this restriction.
I tried setColumns(1) method but it did nothing.
Please help.
Manoj Tyagi
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to create a document. Take a look at the sun tutorial on how to use them. If you don't have any luck post back.
 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
You can extend the JTextField and implement the Key Listener interface. In the keyTeyped() method, u can check the length and consume the keystrokes if the length >= 1.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic