Here you can find the source of ajustarAnchoColumnas(JTable table)
public static void ajustarAnchoColumnas(JTable table)
//package com.java2s; //License from project: Open Source License import java.awt.Component; import javax.swing.JTable; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; public class Main { public static void ajustarAnchoColumnas(JTable table) { TableColumnModel columnModel = table.getColumnModel(); for (int col = 0; col < table.getColumnCount(); col++) { int maxwidth = 0; for (int row = 0; row < table.getRowCount(); row++) { TableCellRenderer rend = table.getCellRenderer(row, col); Object value = table.getValueAt(row, col); Component comp = rend.getTableCellRendererComponent(table, value, false, false, row, col); maxwidth = Math//from ww w . j a va 2 s . c om .max(comp.getPreferredSize().width, maxwidth); } // para fila TableColumn column = columnModel.getColumn(col); column.setPreferredWidth(maxwidth); } // para columnas } }