如是设置表格头的标题

wjfling 2004-06-12 04:41:46
TableColumnModel colModel= table.getColumnModel();
colModel.setColumnMargin(2);
TableColumn col = new TableColumn();
col.setCellRenderer(new DefaultTableCellRenderer());
//这个方法没有成功
col.setHeaderValue(new String("列"+colNum));

colNum++;
colModel.addColumn(col);
table.setColumnModel(colModel);
model.setColumnCount(colNum);

以上向表格是添加新和一列,但如何设置这个列标题.
...全文
93 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
mangob 2004-06-18
  • 打赏
  • 举报
回复
mark
maowu 2004-06-12
  • 打赏
  • 举报
回复
因为在model里记录到你的列数没有增加,
根据文档:
If the new size is greater
than the current size, new columns are added to the end of the model
with <code>null</code> cell values.
所以加了一列name是null的.
maowu 2004-06-12
  • 打赏
  • 举报
回复
那就把这行去掉吧:
model.setColumnCount(colNum);
wjfling 2004-06-12
  • 打赏
  • 举报
回复
TableColumn 为什么不行呢?
maowu 2004-06-12
  • 打赏
  • 举报
回复
你用的是 DefaultTableModel吧?

((DefaultTableModel)model).addColumn(new String("列"+colNum));
就可以了.

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧