void () { DefaultTableColumnModel colModel = (DefaultTableColumnModel)myTable.getColumnModel(); int[] colMinWidths = new int[myColumns.length]; for (int iColumn = 0; iColumn < myColumns.length; iColumn++) { TableColumn col = colModel.getColumn(iColumn); colMinWidths[iColumn] = col.getMinWidth(); if (!myColumns[iColumn].needPack()) { col.setWidth(col.getMinWidth()); continue; } // Get width of column header TableCellRenderer renderer = col.getHeaderRenderer(); if (renderer == null) { renderer = myTable.getTableHeader().getDefaultRenderer(); } Component comp = renderer.getTableCellRendererComponent(myTable, col.getHeaderValue(), false, false, 0, 0); int colWidth = comp.getPreferredSize().width; for (int iRow = 0; iRow < myTable.getRowCount(); iRow++) { renderer = myTable.getCellRenderer(iRow, iColumn); comp = renderer.getTableCellRendererComponent(myTable, myTable.getValueAt(iRow, iColumn), false, false, iRow, iColumn); colWidth = Math.max(colWidth, comp.getPreferredSize().width); } colWidth += 2 * COLUMN_HEADER_MARGIN_WIDTH; col.setMaxWidth(colWidth); col.setMinWidth(colWidth); } for (int iColumn = 0; iColumn < myColumns.length; iColumn++) { TableColumn col = colModel.getColumn(iColumn); col.setMinWidth(colMinWidths[iColumn]); } }