Here you can find the source of calculateColumnWidth(JTable table, int columnIndex)
public static int calculateColumnWidth(JTable table, int columnIndex)
//package com.java2s; import java.awt.Component; import javax.swing.JTable; import javax.swing.table.TableCellRenderer; public class Main { public static int calculateColumnWidth(JTable table, int columnIndex) { int width = 0; // The return value int rowCount = table.getRowCount(); for (int i = 0; i < rowCount; i++) { TableCellRenderer renderer = table.getCellRenderer(i, columnIndex);//from w w w. ja v a 2s .com Component comp = renderer.getTableCellRendererComponent(table, table.getValueAt(i, columnIndex), false, false, i, columnIndex); int thisWidth = comp.getPreferredSize().width; if (thisWidth > width) { width = thisWidth; } } return width; } }