如何在 while 循环中更新 jLabel?我的理解是使用 javax.swing.timer 但是我不太理解它,因为我还需要执行一个操作,现在这是一个 while 循环,每次通过 while 循环时都需要更新一个计数器。
有没有更简单的方法来做到这一点,如果是这样,我应该使用什么来代替 jLabel?
示例代码低于我需要更新的内容。
int rowCount = 0;
while(rowIterator.hasNext())
{
jLabel5.setText(""+ rowCount); //<-- i need this to update
myRow = sheet.getRow(count);
cellIterator = myRow.cellIterator();
Cell myCell2 = myRow.getCell(0);
nextCell= myCell2.getStringCellValue();
if(nextCell.equals(firstCell))
{
while(cellIterator.hasNext()) {
Cell cell = cellIterator.next();
switch(cell.getCellType()) {
case Cell.CELL_TYPE_BOOLEAN:
System.out.print(cell.getBooleanCellValue() + "\t\t");
break;
case Cell.CELL_TYPE_NUMERIC:
cell.setCellType(Cell.CELL_TYPE_STRING);
System.out.print(cell.getStringCellValue()+",");
//System.out.print(cell.getStringCellValue() + "\t\t");
writer.write(cell.getStringCellValue()+",");
break;
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue()+",");
//System.out.print(cell.getStringCellValue() + "\t\t");
writer.write(cell.getStringCellValue()+",");
break;
}
}
System.out.println();
writer.newLine();
count++;
rowCount++;
}
else
{
writer.close();
myRow = sheet.getRow(count);
myCell2= myRow.getCell(0);
nextCell=myCell2.getStringCellValue();
firstCell=nextCell;
Matter = "Matter Number: "+firstCell;
num = firstCell;
System.out.println(Matter);
fWriter = new FileWriter(new File(directory, num+"_"+curdate+"_"+curtime+".csv"));
writer = new BufferedWriter(fWriter);
writer.write(Matter);
writer.newLine();
writer.write(header);
writer.newLine();
}
}
}
catch (Exception e)
{
}