【发布时间】:2013-03-06 07:37:57
【问题描述】:
如何在 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)
{
}
【问题讨论】:
标签: java apache-poi jlabel auto-update