Your second demo was a conversion of a py5 demo to a Processing app, and I use a separate EventDispatchThread in Processing apps at the recommendation of others in this forum:
https://discourse.processing.org/t/swing-components-in-default-processingwindow/35483
However, I have not been using a separate thread for Swing components in py5 simply because it has never caused any problems as far as I’m aware and I am unable to find any good references on how to add it in Python. Py5 appears to have insulated us from this problem, but I am not aware of how this has been accomplished under the hood; I have not dissected the source code. The issue has recently come up in their forum with regard to using Swing components without using py5 and here a separate thread seems to be necessary also. Furthermore, source code posted in JPype documentation which deals with Swing components and a separate EventDispatchThread won’t run on a Mac for some reason and as far I know there is no published fix for Macs: https://jpype.readthedocs.io/en/latest/userguide.html#awt-swing. It’s in the AWT/Swing section. I would love for somebody to show me how it’s done or find it published somewhere, but I can’t find it. The only reason I use it in Processing is because I was cautioned when I posted the first demo here some time back (referenced above), and it seems pretty well accepted that Swing is not ‘thread safe’, whatever that entails. I respect the experiences of others. When I use Swing components in Processing I frequently remove the canvas, so there is no draw() available to use. Perhaps it’s still being used by the runtime, I don’t know about that. DotView, recently published, preserves part of the canvas so draw() is functional in this instance.