I\'m trying to write application which need to draw many strings using Graphics2D class in Java. I need to get sizes of each String object (to calculate exact p
Graphics2D
Try with the FontMetrics class; the stringWidth method returns the size of a string. An example:
JComponent c = getSomeKindOfJComponent(); FontMetrics fm = c.getFontMetrics(c.getFont()); // or another font int strw = fm.stringWidth("My text");