| Author |
How to set maxlength for java.awt.TextField
|
solomon alexander
Greenhorn
Joined: Mar 20, 2007
Posts: 19
|
|
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
Joined: Mar 20, 2007
Posts: 19
|
|
Hi,
Can anyone reply to my question?
Alex
|
 |
K. Tsang
Ranch Hand
Joined: Sep 13, 2007
Posts: 1219
|
|
|
You can't. You need to detect it yourself using KeyListener/KeyAdapter or DocumentListener.
|
K. Tsang JavaRanch SCJP5 SCJD/OCM-JD
|
 |
bhagya hari
Greenhorn
Joined: Oct 15, 2008
Posts: 5
|
|
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
Joined: Jun 06, 2007
Posts: 2552
|
|
|
"bhagya hb " please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.
|
SCJP, SCWCD.
|Asking Good Questions|
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
solomon alexander
Greenhorn
Joined: Mar 20, 2007
Posts: 19
|
|
Hi Rob,
Thanks a lot. TextListener worked for me.
Regards
Solomon
|
 |
 |
|
|
subject: How to set maxlength for java.awt.TextField
|
|
|