Here you can find the source of setSize(JTable table, int columnIndex, int newSize)
public static void setSize(JTable table, int columnIndex, int newSize)
//package com.java2s; //License from project: Apache License import javax.swing.*; import javax.swing.table.TableColumn; import java.awt.*; public class Main { public static void setSize(JTable table, int columnIndex, int newSize) { TableColumn column = table.getColumnModel().getColumn(columnIndex); setSize(table, column, newSize); }/* w ww. j a va 2s .co m*/ public static void setSize(JTable table, TableColumn column, int newSize) { newSize += getIntercellWidth(table); column.setMinWidth(newSize); column.setMaxWidth(newSize); column.setPreferredWidth(newSize); column.setWidth(column.getPreferredWidth()); } public static int getIntercellWidth(JTable table) { return (int) table.getIntercellSpacing().getWidth(); } public static int getPreferredWidth(Component component) { return (int) (component.getPreferredSize().getWidth() + 1); } }