不要緊,你是否滾動多或只有一個字段:根本問題是讓水平滾動條來開始:-)
有來調整兩個螺絲: - 使水平滾動條通過設置表格的resizeMode:默認值始終適合表格的大小以適應scrollPane的大小,即不滾動 - 調整列寬以適應其內容的大小
在覈心JTable中映射到類似僞代碼
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
// on receiving a TableModelEvent which might increase the column width
// calculate new width by measuring pref of the renderer
int newWidth = ...
// set it as pref of the column
table.getColumnModel().getColumn(0).setPreferredWidth(newWidth);
問題是,如果沒有resizeMode,你總是要負責調整列的大小:它的寬度小於scrollPane,它的尾部有一個空的區域。
JXTable(的SwingX project部分),支持其中只要填充可用水平空間爲表的prefWidts加成上漿模式小於父寬度和示出,如果需要
table.setHorizontalScrollEnabled(true);
// on receiving a TableModelEvent which might increase the column width
// tell the table to re-evaluate
table.packColumn(0);
1)一定要在問題中添加問號。 2)爲了更快地獲得更好的幫助,請發佈[SSCCE](http://sscce.org/)。 –