List of utility methods to do Font Text Bounds
Rectangle2D | getTextBounds(Graphics g, String text) Returns text bounds for specified graphics context. FontMetrics fm = g.getFontMetrics();
return fm.getStringBounds(text, g);
|
Rectangle | getTextBounds(Graphics graphics, String text) Get the bounds for drawing the specified text in the specified graphics context. FontMetrics metrics = graphics.getFontMetrics(); Rectangle2D textBounds = metrics.getStringBounds(text, graphics); int textAscend = metrics.getMaxAscent(); return new Rectangle(0, textAscend, (int) textBounds.getWidth(), textAscend + metrics.getMaxDescent()); |
Rectangle2D | getTextBounds(Graphics2D g, Font font, String text) Get Bounding box for some text FontMetrics metric = g.getFontMetrics(font);
return metric.getStringBounds(text, g);
|
Rectangle2D | getTextBounds(String text, Graphics2D g2, FontMetrics fm) Returns the bounds for the specified text. double width = fm.stringWidth(text); double height = fm.getHeight(); return new Rectangle2D.Double(0.0, -fm.getAscent(), width, height); |
Rectangle2D | getTextBox(Font font, FontRenderContext frc, boolean withLeading, String text) Returns a rectangle that contains the supplied text with space around the text for an aesthetically pleasing border. Rectangle2D bounds = getBounds(new TextLayout(text, font, frc), withLeading); return pad(bounds, 2 * HEADER_BORDER, 2 * HEADER_BORDER); |