首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Jtabe更新数据后,table护持列宽

2013-08-01 
Jtabe更新数据后,table保持列宽public class TableSaveAutoColumnSize {?? ? ListTableColumn tableColu

Jtabe更新数据后,table保持列宽

public class TableSaveAutoColumnSize {

?

? ? List<TableColumn> tableColumnList = new ArrayList<TableColumn>();

? ? JTable table;

?

? ? public TableSaveAutoColumnSize(JTable table) {

? ? ? ? this.table = table;

? ? ? ? saveAutoColumnSize();

? ? }

?

? ? public void saveAutoColumnSize() {

? ? ? ? TableColumnModel tcm = table.getColumnModel();

? ? ? ? Enumeration<TableColumn> cm = tcm.getColumns();

? ? ? ? while (cm.hasMoreElements()) {

? ? ? ? ? ? TableColumn tt = cm.nextElement();

? ? ? ? ? ? tableColumnList.add(tt);

? ? ? ? }

? ? }

?

? ? public void resetWithAutoColumnSize() {

? ? ? ? TableColumnModel tcm = table.getColumnModel();

? ? ? ? Enumeration<TableColumn> cm = tcm.getColumns();

? ? ? ? int j = 0;

? ? ? ? while (cm.hasMoreElements()) {

? ? ? ? ? ? TableColumn tt = cm.nextElement();

? ? ? ? ? ? tt.setWidth(tableColumnList.get(j).getWidth());

? ? ? ? ? ? tt.setPreferredWidth(tableColumnList.get(j).getPreferredWidth());

? ? ? ? ? ? j++;

? ? ? ? }

? ? }

}

?

使用方式:

? ? ? ? ? ? TableSaveAutoColumnSize ts = new TableSaveAutoColumnSize(table);

? ? ? ? ? ? model.setDataVector(data, title);

? ? ? ? ? ? ts.resetWithAutoColumnSize();

?

?

热点排行