public class HiwayTest6 { public static void main(String...args){
JFrame frame = new JFrame("Test");
Vector rowData = new Vector();
Vector column = new Vector();
for(int i=0;i<10;i++){
Vector vec = new Vector();
for(int j=0;j<10;j++){
vec.add("("+i+","+j+")");
}
rowData.add(vec);
}
for(int i=0;i<10;i++){
column.add(i);
}
DefaultTableModel model = new DefaultTableModel(rowData,column);
JTable table = new JTable(model);
model.addColumn("add1");
table.addColumn(new TableColumn(1));
System.out.println(model.getColumnCount()+"\t"+table.getColumnCount()+"\t"+table.getTableHeader().getColumnModel().getColumnCount()+"\t"+table.getColumnModel().getColumnCount());
frame.setContentPane(new JScrollPane(table));
frame.setBounds(new Rectangle(10,10,800,600));
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
the output:
11 12 12 12why ?
解决方案 »
- 请问一个工程有多个package怎么用-jar打包?
- 游戏背景移动时有点小卡,希望能有人指点一下可能是什么原因。
- groovy 到底是编译型语言 or 解释型语言???
- 问个技术难题,发现中文的资料很少,希望大家给点idea
- 求chm格式的中文servlet api?能否发一个
- 小妹有个问题,希望高手帮忙!!!
- mysql的驱动为什么放在jdk的ext里才好用?
- 想请懂java的朋友帮个忙:java中类与类之间的转换,需要调用那些函数
- sybase中返回最初的10条怎么写?
- 如何配置tomcat3.3.2,?
- 关于创建对象的问题,和创建数组对象!!求高手,小弟请教!!!
- 菜鸟求指点 怎么样在一个类中集中处理异常啊
那如何让TableModel得到信息呢?another question:
add these two lines:table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setPreferredSize(new Dimension(1200,400));I put JTable in a JScrollPane, then set PreferredSize to make sure HorizontalScrollBar to be shown.But now when I drag the horizontalBar, the tabelHeader doesn't update.How to solve it ? Thank you
I solve the tableHeader question:
add this line of code:table.getTableHeader().setPreferredSize(new Dimension(1200,20));dear huntor:
can you help me to solve the tableModel and tableColumnModel question?Thank you