I'd like to use SftpProgressMonitor
's count()
method to update the percentage of completion of a SFTP operation. I know it is better to use Worker threads in order not to block the UI, but I am curious on why this code does not update the table until the SFTP operation has completed:
public class MySftpProgressMonitor implements SftpProgressMonitor {
JTable table = getTableReference();
DefaultTableModel tableModel = getTableModelReference();
@Override
public boolean count(long bytes) {
int percentage = computePercentage(bytes);
table.setValueAt(percentage, 0, 1);
return true;
}
@Override
public void end() {
}
@Override
public void init(int op, String src, String dest, long maxBytes) {
Object[] rowData = {src, 0};
tableModel.addRow(rowData);
}
}
I don't see anything happening on the UI until the file transfer is completed (I see an entry whose percentage is 100%) and I wonder why. Since I am not using any additional threads, this code gets executed on the EDT, so it should be able to update UI components. I am also trying to explicitly call repaint()
, table.repaint()
and revalidate()
but nothing happens.
I am reading TFM but can't figure out what is the error here. Thank you.