0

Rendering a textbox of a fixed length of characters

asked 2012-04-27 03:44:33 +0800

rcaschultz gravatar image rcaschultz
27

I have a need to specify a textbox of a given width of characters. How do I do that? I tried textbox.setCols() expecting that to work, and it did not. I know I can specify the number of pixels, but not sure how to convert the length of a string into pixels since font sizes and zoom may vary in a user's browser. Any thoughts would be most appreciated..

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2012-04-27 14:47:42 +0800

rcaschultz gravatar image rcaschultz
27

Thanks. I had already done that - but to me its a bit of a hack. Depending upon the font chosen for rendering the textbox, the 10px may be too much or too little. At least with Intbox I can setMaxlength and restrict the amount of entry - but the Intbox itself still renders much longer than the allowed entry.

link publish delete flag offensive edit

answered 2012-04-27 06:59:07 +0800

siva477 gravatar image siva477
57

Try this...

int lengthOfChars = String.getLength();

textbox.setWidth(lengthOfChars *10+"px");

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-04-27 03:44:33 +0800

Seen: 185 times

Last updated: Apr 27 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More