简体   繁体   English

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

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

sorry if my question looks stupid but I'm not really good at For loops.对不起,如果我的问题看起来很愚蠢,但我并不擅长 For 循环。 My window looks like this.我的窗户看起来像这样。

jFrame框架

When I click on "valider", I want to add every rows in the Prix column to a variable Total.当我点击“valider”时,我想将 Prix 列中的每一行添加到变量 Total 中。 Here is my loop:这是我的循环:

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

When I check what's in my Total variable, it just gives me the content of the last row.当我检查 Total 变量中的内容时,它只给我最后一行的内容。

Could you guys help me with this loop ?你们能帮我解决这个循环吗?

Problem is you have used an invalid assignment Operator .问题是您使用了无效的赋值运算符。 =+ should be change as += to get your expected answer . =+ 应该更改为 += 以获得您预期的答案。


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