我需要找到在屏幕上繪製的文本的寬度。 This thread表明FontMetrics.stringWidth()有時不會像FontMetrics.getStringBounds()那樣精確。FontMetrics.stringWidth()和FontMetrics.getStringBounds()有什麼區別?
有誰知道這是否正確,如果是,在哪種情況下這種差異是可見的? FontMetrics.stringWidth()似乎更頻繁地使用,包括在SwingUtilities.computeStringWidth()中。另外,顯而易見的優勢是它不需要Graphics對象,但這本身結合在Graphics對象中定義的抗鋸齒和類似設置的事實可能解釋了爲什麼FontMetrics.getStringBounds()可能更準確。
另請參閱此問題[問與答](http://stackoverflow.com/questions/5979795/how-to-calculate-the-number-of-rows-and-columns-in-each-rowa-a-文本通吃的-AJ/5998117#5998117)。 – trashgod