This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calculate text length

 
Nicholas Turner
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to in jsp or a servlet calculate the width of a string if i know the font size,type and string?
how would I do this?
 
Andy Bowes
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that there is anyway to do this within a servlet as the rendering of the HTML is performed by the client's browser.
The width of a field or portion of text is determined by all sorts of variables such as the fonts that are actually installed on the clients PC, the preferred text size set by the user etc... This information is not passed to the servlet at all therefore the width cannot be determined.
Sorry I can't provide a solution
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic