how to get the width and height of a string in java

Solutions on MaxInterview for how to get the width and height of a string in java by the best coders in the world

showing results for - "how to get the width and height of a string in java"
Caroline
30 May 2019
1String text = "Hello World";
2Font font = new Font("Arial", Font.PLAIN, 12);
3FontRenderContext frc = new FontRenderContext(new AffineTransform(), true, true);
4
5int textwidth = (int)(font.getStringBounds(text, frc).getWidth());
6int textheight = (int)(font.getStringBounds(text, frc).getHeight());
queries leading to this page
java getting width of stringget size of a string javaget size of string in javajava calc font widthget width of a string javasize of string javaget string size javajva get drawn fpnt widthjava measure size of string in fontjava awt getstringwidthjava get width of stringstring length javahow to find the size of string in javajava string size 28 29get width of a drawstring javahow to get the length of a string in javascreipthow to calculate the size of a string in ajvajava calculate size of html texthow to measure the width of a string in javajava swing get text length in pixelshow to get the size of a string in javaget string size in width javajava swing get string heightcalculate size of pixels of a graphics stringget string width javajava get string sizehow to get the size of string in javahow to get the width and height of a string in javajava text length pixelshow to get string size in javajava how to get width and height of stringhow to get size of string javahow to get the size in pixels of a string javajframe get string widthhow to find size of a string in javajava swing get test length in pixelsstring height in javalength of string in pixels javajava swing graphics get string widthheight of string in graphics2djava get string widthget size of string javajava get lenght of a drawn stringlength of string in graphics2dhow to get width of string javahow to get size of a string javajava get size of stringcalculate size of a string javajava string get sizejava graphics get string widthhow to get the width and height of a string in java