Graceful exception handling in Swing Worker

前端 未结 4 838
春和景丽
春和景丽 2020-12-08 20:47

I am using threading in application through Swing Worker class. It works fine, yet I have a bad feeling about showing an error message dialog in try-catch block. Can it pote

4条回答
  •  情书的邮戳
    2020-12-08 21:28

    You are right, you are violating the cardinal rule of Swing, which is don't modify the GUI anywhere except for on the event-dispatch-thread.

    If it was me, I would throw an event that the GUI listens for to show the error message. Or, you can just wrap the invocation of the SwingWorker in a try catch and show the dialogue there.

提交回复
热议问题