Here you can find the source of getTextBounds(Graphics g, String text)
Parameter | Description |
---|---|
g | Graphics context. |
text | Text to be drawn. |
public static Rectangle2D getTextBounds(Graphics g, String text)
//package com.java2s; /* ODISP -- Message Oriented Middleware * Copyright (C) 2003-2005 Valentin A. Alekseev * Copyright (C) 2003-2005 Andrew A. Porohin * /*w ww . ja va 2 s. co m*/ * ODISP is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 2.1 of the License. * * ODISP is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with ODISP. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.geom.Rectangle2D; public class Main { /** * Returns text bounds for specified graphics context. * * @param g Graphics context. * @param text Text to be drawn. * @return Bounds of the text. */ public static Rectangle2D getTextBounds(Graphics g, String text) { FontMetrics fm = g.getFontMetrics(); return fm.getStringBounds(text, g); } }