Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set maxlength for java.awt.TextField

 
solomon alexander
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Could anyone let me know on how to set the maxlength for a field of type java.awt.TextField in Applet?

Thanks
Alex
 
solomon alexander
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anyone reply to my question?

Alex
 
K. Tsang
Bartender
Posts: 3521
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't. You need to detect it yourself using KeyListener/KeyAdapter or DocumentListener.
 
bhagya hari
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no direct method for this.

You can create a customized Textfield extends JTextField. In the constructor use the class which extends PlainDocument.
By overriding the method insertString in PlainDocument interface you can allow the user to enter only the specified number of character.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"bhagya hb " please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang and bhagya hari, I think both of you missed that it is an AWT TextField, not a JTextField.

Solomon, you could try using a TextListener. Or of course change your code to use Swing (and JApplet, JTextField). Not only does it look better, it's also a lot more powerful.
 
solomon alexander
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

Thanks a lot. TextListener worked for me.

Regards
Solomon
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic