我最近查看了整个SwingWorker的事情,我发现它非常有用所以我决定尝试一下,但尽管每个人都说 - 它继续挂起我的应用程序。
这是我的SwingWorker代码:
final ArrayList<Farm> farmz = dm.loadAll(item);
SwingWorker<Boolean, Farm> worker = new SwingWorker<Boolean, Farm>() {
@Override
protected Boolean doInBackground() throws Exception {
for (int i = 0; i < farmz.size(); i++) {
publish(farmz.get(i));
}
return true;
}
@Override
protected void done() {
try {
boolean status = get();
if (status) {
log.info("Completed loading!");
allModel.fireTableDataChanged();
} else {
log.info("Failed to load...");
}
} catch (InterruptedException e) {
} catch (ExecutionException e) {
}
}
protected void process(List<Farm> frm) {
for (Farm farm : frm) {
allModel.addRow(farm);
}
}
};
worker.execute();
我认为我已经正确地遵循了一切,但我仍然对这个问题感到头疼。