JTable默認情況下

若要根據內容來調整列寬
[java]
int maxwidth =
for (int row=
TableCellRenderer rend = table
Object value = table
Component comp =
rend
value
false
false
row
col);
maxwidth = Math
maxwidth);
}
這段代碼是在計算列內容中的最大值maxwidth
[java]
Object value = table
如果不了解MVC模型和JTable的渲染器的話
getTableCellRendererComponent方法應該是jtable調用來把數據模型的數據渲染成component

上圖已經是根據內容調整列寬了
不過思路也是一樣的
[java]
TableCellRenderer headerRenderer = column
if (headerRenderer == null)
headerRenderer = table
Object headerValue = column
Component headerComp =
headerRenderer
headerValue
false
false
col);
maxwidth = Math
headerComp

From:http://tw.wingwit.com/Article/program/Java/ky/201311/28729.html