Java 如何向jTable添加列并动态填充
我有一个4列6行的Jtable和一个jButton。单击jButton时,将运行查询,结果存储在字符串变量中。在查询成功完成后,将调用其他代码以向现有jTable添加列。我的问题是如何用字符串变量中的数据填充新创建的列。我使用下面的代码Java 如何向jTable添加列并动态填充,java,swing,for-loop,jtable,Java,Swing,For Loop,Jtable,我有一个4列6行的Jtable和一个jButton。单击jButton时,将运行查询,结果存储在字符串变量中。在查询成功完成后,将调用其他代码以向现有jTable添加列。我的问题是如何用字符串变量中的数据填充新创建的列。我使用下面的代码 for(int col = 0; col<jTable2.getRowCount(); col++){ TableColumn c = new TableColumn();
for(int col = 0; col<jTable2.getRowCount(); col++){
TableColumn c = new TableColumn();
c.setHeaderValue("Test");
((DefaultTableModel) jTable2.getModel()).addColumn(c);
jTable2.setValueAt("100", col, 12);
}
for(int col=0;col在for循环外添加列,并在循环中为每行设置值。@KDM thanx problem solved删除注释并将其作为答案添加。