Here you can find the source of getPreferredRowHeight(JTable table, int rowIndex, int margin)
private static int getPreferredRowHeight(JTable table, int rowIndex, int margin)
//package com.java2s; /*/*from w w w. ja v a2 s . c om*/ Copyright 2011 Udayakumar Dhansingh (Udy) Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import java.awt.Component; import javax.swing.JTable; import javax.swing.table.TableCellRenderer; public class Main { private static int getPreferredRowHeight(JTable table, int rowIndex, int margin) { // Get the current default height for all rows int height = table.getRowHeight(); // Determine highest cell in the row for (int c = 0; c < table.getColumnCount(); c++) { TableCellRenderer renderer = table.getCellRenderer(rowIndex, c); Component comp = table.prepareRenderer(renderer, rowIndex, c); int h = comp.getPreferredSize().height + 2 * margin; height = Math.max(height, h); } return height; } }