Here you can find the source of getRowHeight(java.awt.Component c)
public static int getRowHeight(java.awt.Component c)
//package com.java2s; /******************************************************************************* * Copyright (C) 2006-2013 AITIA International, Inc. * // w w w.j av a 2s . co m * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. ******************************************************************************/ public class Main { private static java.awt.Component g_referenceComponent = null; /** Returns the row height (font height) of 'c' of the reference component if 'c' * is null. */ public static int getRowHeight(java.awt.Component c) { java.awt.Font f = (c != null) ? c.getFont() : null; if (f == null) f = getRefComp().getFont(); if (f == null) f = javax.swing.UIManager.getFont("Label.font"); return (c != null ? c : getRefComp()).getFontMetrics(f).getHeight(); } /** * Some functions (such as font/screen size calculation) require a component * e.g. to access the screen. I call it as 'reference component'. * It is recommended to set it to a JLabel/JButton in the main window. */ public static java.awt.Component getRefComp() { if (g_referenceComponent == null) { g_referenceComponent = java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); if (g_referenceComponent == null) g_referenceComponent = new javax.swing.JLabel(); } return g_referenceComponent; } }