0

Would it be possible to get the width of a string based on its font?

So for example, if the font size is 40, and the string was "hi", could you do 2*40.

An example of this would be

startX = 260; startWidth = "Start".length()*getFont().getSize();
startY = getHeight()-startWidth-20; 
startHeight = getFont().getSize();
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
isxana
  • 11
  • 1
  • 1
  • 3

1 Answers1

0

It really depends on the type of font, whether it's monospaced or proportional. Most font now are proportional so you would not simply be able to calculate num_of_chars * n.

The gui interface you are using should give you the width of the container once it has been populated with the given text.

johnflan
  • 321
  • 4
  • 15