Here you can find the source of getFRC(JComponent c, FontMetrics fm)
private static FontRenderContext getFRC(JComponent c, FontMetrics fm)
//package com.java2s; /******************************************************************************* * Copyright (C) 2011 Atlas of Living Australia * All Rights Reserved.//w ww .j a v a 2 s . com * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. ******************************************************************************/ import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Toolkit; import java.awt.font.FontRenderContext; import javax.swing.JComponent; public class Main { /** * Returns the FontRenderContext for the passed in FontMetrics or for the passed in JComponent if FontMetrics is null */ private static FontRenderContext getFRC(JComponent c, FontMetrics fm) { if (fm == null && c != null) { // we do it this way because we need first case to // work as fast as possible return getFRC(c, c.getFontMetrics(c.getFont())); } return null; } /** * Returns the FontMetrics for the current Font of the passed in Graphics. This method is used when a Graphics is available, typically when painting. If a * Graphics is not available the JComponent method of the same name should be used. * <p> * Callers should pass in a non-null JComponent, the exception to this is if a JComponent is not readily available at the time of painting. * <p> * This does not necessarily return the FontMetrics from the Graphics. * * @param c * JComponent requesting FontMetrics, may be null * @param g * Graphics Graphics */ public static FontMetrics getFontMetrics(JComponent c, Graphics g) { return getFontMetrics(c, g, g.getFont()); } /** * Returns the FontMetrics for the specified Font. This method is used when a Graphics is available, typically when painting. If a Graphics is not available * the JComponent method of the same name should be used. * <p> * Callers should pass in a non-null JComonent, the exception to this is if a JComponent is not readily available at the time of painting. * <p> * This does not necessarily return the FontMetrics from the Graphics. * * @param c * JComponent requesting FontMetrics, may be null * @param c * Graphics Graphics * @param font * Font to get FontMetrics for */ @SuppressWarnings("deprecation") public static FontMetrics getFontMetrics(JComponent c, Graphics g, Font font) { if (c != null) { // Note: We assume that we're using the FontMetrics // from the widget to layout out text, otherwise we can get // mismatches when printing. return c.getFontMetrics(font); } return Toolkit.getDefaultToolkit().getFontMetrics(font); } }