簡體   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