【发布时间】:2019-09-23 05:44:38
【问题描述】:
我正在尝试使用 for 循环从我的 Jtable 中获取行数据,但它给出了最后一行。下面是我的代码示例:
String item = null; String qty = null; String price = null;
for (int i = 0; i < table.getRowCount(); i++) {
String f1 =item.getValueAt(i, 0).toString();
String f2 =item.getValueAt(i, 1).toString();
String f3 =item.getValueAt(i, 2).toString();
item = f1; qty = f2; price =f3;
}
Formatter fd = new Formatter();
System.out.println(fd.format("%-20s %5s %10s", item ,qty ,price ));
【问题讨论】:
-
您希望得到什么结果?从您发布的代码中,很明显只有最后一个表格行将通过调用方法
println()打印出来。您是否尝试调试您发布的代码? -
我想获取for循环外的所有行数据?
标签: java swing for-loop iteration