我正在尝试填充一组双精度元素,这些元素存储在一个JTable列中,我尝试使用"for“循环,但算法并不相关:
 for (int i = 0 ; i < nRow ; i++)
 {
     double ad [ ] = { (double)dtm.getValueAt(i, 1)};
 }问题是,当"i“变量等于一个新值(例如1或2)时,最后一个值会被新值替换。
什么算法允许填充集合?
发布于 2015-05-03 10:40:34
感谢@camick和@madprogrammer更新了代码,根据需求这可能是最优的。
public Object[] getColumnData(JTable table, int targetColIndex) {
DefaultTableModel dtm = (DefaultTableModel) table.getModel();
int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount();
if(table== null)
    return null;
if(targetColIndex > nCol)
    return null;
Object[] tableData = new Object[nRow];
for (int i = 0 ; i < nRow ; i++)
   tableData[i] = dtm.getValueAt(i,targetColIndex);
return tableData;
}嗨,检查上面的内容可能会对你有所帮助。
https://stackoverflow.com/questions/30009601
复制相似问题