繁体   English   中英

如何在变量中添加 jTable 不同行的内容?

[英]How can I add content of different rows of my jTable in a variable?

对不起,如果我的问题看起来很愚蠢,但我并不擅长 For 循环。 我的窗户看起来像这样。

框架

当我点击“valider”时,我想将 Prix 列中的每一行添加到变量 Total 中。 这是我的循环:

float total = 0;
 for (int i = 0; i < jTable4.getRowCount(); i++)
 total =+ (float) jTable4.getValueAt( i, 2);

当我检查 Total 变量中的内容时,它只给我最后一行的内容。

你们能帮我解决这个循环吗?

问题是您使用了无效的赋值运算符。 =+ 应该更改为 += 以获得您预期的答案。


float total = 0;
for (int i = 0; i < jTable4.getRowCount(); i++) {  // Loop through the rows
       
        total += (float) jTable4.getValueAt(i, 2);  
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM