gpt4 book ai didi

java - 如何计算 JTable 中的非空行?

转载 作者:行者123 更新时间:2023-11-30 08:44:43 24 4
gpt4 key购买 nike

我需要返回 JTable 的非空行数的函数。getRowCount() 给出 Jtable 中不需要的总行数(空+填充=)。

JTable

最佳答案

我没有使用 JTables 的经验,所以我不确定这是否是“最佳”解决方案,但我能想到的一种非常简单的方法是遍历每一行并检查是否所有该行的列中的值为空。如果所有列都为空,则将空行数增加一并在函数末尾返回该值:

public int emptyRows(JTable table) {
int emptyRows = 0;
rowSearch: for (int row = 0; row < table.getRowCount(); row++) { //Iterate through all the rows
for (int col = 0; col < table.getColumnCount(); col++) { //Iterate through all the columns in the row
if (table.getValueAt(row, col) != null) { //Check if the box is empty
continue rowSearch; //If the value is not null, the row contains stuff so go onto the next row
}
}
emptyRows++; //Conditional never evaluated to true so none of the columns in the row contained anything
}
return emptyRows;
}

关于java - 如何计算 JTable 中的非空行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33659081/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com