Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to set maxlength for java.awt.TextField

 
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
 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser 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.
 
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.
 
Bartender
Posts: 2856
10
Firefox Browser Fedora 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.
 
Sheriff
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
 
    Bookmark Topic Watch Topic
  • New Topic