Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resticting Textfield Size

 
Rajasree R
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to have a textfield which accepts limited number of characters.This can be done using JFormattedTextField.But how can I restict the size of the textfield to accept only that many characters.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uh, you answered your own question. Say you wanted to limit youself to 4 numbers.

MaskFormatter mf = new MaskFormatter("####");
JFormattedTextField tf = new JFormattedTextField(mf);
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some other options if you find MaskFormatter doesn't meet your needs.
 
Rajasree R
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
My problem is not that.Restict the SIZE OF TEXTFIELD.not the number of characters in that..ie,the size(display) of textfield should be resticted accoring to the number of characters..
 
Swati Udas
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well that sounds even simpler..
I guess u can use the right constructor for the textfield

JTextField txt=new JTextField("String",30);

so now u have a textfield which will be shown with size 30 on ur UI..irrespective of the stringlength displayed inside this field.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic