如何使 SwingWorker 多次启动..?

How to make a SwingWorker Start more than once..?

如图所示,我创建了一个名为 "filter" 的按钮,用于根据当前 status.I 筛选出特定数据集 status.I 使用 SwingWorker 从 database.The 代码中检索数据我现在工作正常。单击按钮后,它会显示相关数据。但是当我以不同的状态再次单击它时,它没有显示所需的 data.I 正在阅读 doingBackground 方法只会执行一次。有没有什么办法可以重新启动它..??

您无法重启 SwingWorker,而且您也不想重启。根据 SwingWorker API:

SwingWorker is only designed to be executed once. Executing a SwingWorker more than once will not result in invoking the doInBackground method twice.

您的解决方案是在按钮的 ActionListener 中创建一个新的 SwingWorker 实例并执行它;这样做,你可能会没事的。